🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / Java / thread sayac örnekleri multi

 

1-) Java - thread sayac örnekleri multi

 

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        

        Thread th1 = new Thread(() -> {

            try {

                ThreadSafe1.b();

            } catch (InterruptedException ex) {

                Logger.getLogger(JavaApplication41.class.getName()).log(Level.SEVERE, null, ex);

            }

        }, "Thread1");

        Thread th2 = new Thread(() -> {

            try {

                ThreadSafe1.a();

            } catch (InterruptedException ex) {

                Logger.getLogger(JavaApplication41.class.getName()).log(Level.SEVERE, null, ex);

            }

        }, "Thread2");

        th1.start();

        th2.start();

 

    }                                        

    static class ThreadSafe1 {

  static int sayac=0;

        public static void a() throws InterruptedException {

          

            while (1 == 1) {

                

               

                jLabel1.setText("ramo"+sayac++);

                Thread.sleep(500);

            }

        }

 

        public static void b() throws InterruptedException {

            while (1 == 1) {

                System.out.println("ramazan");

                StringBuilder builder = new StringBuilder();

                builder.append("haber"+sayac++);

                jLabel2.setText(builder.toString());

                Thread.sleep(500);

            }

        }

 

    }

 2021 Ocak 18 Pazartesi
 416