Introduction to multithreading

Source: Internet
Author: User

Package com. xml. test;

Public class MyThread {

/**
* @ Param args
*/Www.2cto.com
Int j;
Public synchronized void inc (){
J ++;
System. out. println (Thread. currentThread (). getName () + "-- inc" + j );
}
Public synchronized void des (){
J --;
System. out. println (Thread. currentThread (). getName () + "-- des" + j );
}
Class InnerClass_a implements Runnable {
Public void run (){
For (int I = 0; I <100; I ++ ){
Inc ();
}
}
}
Class InnerClass_ B implements Runnable {
Public void run (){
For (int I = 0; I <100; I ++ ){
Des ();
}
}
}
Public static void main (String [] args ){
 
MyThread mythread = new MyThread ();
InnerClass_a class_a = mythread. new InnerClass_a ();
InnerClass_ B class_ B = mythread. new InnerClass_ B ();
For (int I = 0; I <1; I ++ ){
Thread thread_a = new Thread (class_a );
Thread_a.start ();
Thread thread_ B = new Thread (class_ B );
Thread_ B .start ();
}
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.