package com.jalja.org.thread.demo01;
public class Thread02 {
public synchronized void method1(){
System.out.println("method1:"+Thread.currentThread().getName());
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public synchronized void method2(){
System.out.println("method2:"+Thread.currentThread().getName());
}
public static void main(String[] args) {
final Thread02 th=new Thread02();
Thread thread1=new Thread(new Runnable() {
public void run() {
th.method1();
}
},"th1");
Thread thread2=new Thread(new Runnable() {
public void run() {
th.method2();
}
},"th2");
thread1.start();
thread2.start();
}
}
package com.jalja.org.thread.demo01;
public class Thread02 {
public synchronized void method1(){
System.out.println("method1:"+Thread.currentThread().getName());
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void method2(){
System.out.println("method2:"+Thread.currentThread().getName());
}
public static void main(String[] args) {
final Thread02 th=new Thread02();
Thread thread1=new Thread(new Runnable() {
public void run() {
th.method1();
}
},"th1");
Thread thread2=new Thread(new Runnable() {
public void run() {
th.method2();
}
},"th2");
thread1.start();
thread2.start();
}
}
package com.jalja.org.thread.demo01;
public class Thread03 {
private String name="zs";
private String passWorrd="123";
public synchronized void setValue(String name,String passWord){
this.name=name;
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
this.passWorrd=passWord;
System.out.println("set:name="+this.name +" passWorrd="+this.passWorrd);
}
public void getValue(){
System.out.println("get:name="+this.name +" passWorrd="+this.passWorrd);
}
public static void main(String[] args) throws InterruptedException {
final Thread03 th=new Thread03();
Thread thread=new Thread(new Runnable() {
public void run() {
th.setValue("LS", "456");
}
});
thread.start();
Thread.sleep(100);
th.getValue();
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有