Monday, January 4, 2016

Java Thread Example 2

Using Thread
Concurrency and simple thread synchronization
Тред зэрэг ачаалах /
Энгийн хэвлэх функц:
    public synchronized void doStuff(String threadname){
        jTextArea1.append(threadname + " access started...\n");
        jTextArea1.append("Doing stuff...\n");
        jTextArea1.append(threadname + " access finished...\n");
    }
Товчны дарах үзэгдэл дээр бичих:
        for(int i = 0; i<10; i++){
            Thread t1 = new Thread(){
              public void run()   {    doStuff("thread1");     }     };
            Thread t2 = new Thread(){
                public void run(){     doStuff("thread2");     }     };
            t1.start();
            t2.start();
        }
Үр дүн:
synchronized ашиглаагүй:

synchronized ашигласан:

линк: https://www.youtube.com/playlist?list=PL8F0C07390BAC102A

No comments:

Post a Comment