package demo;
public class TesA {
public static void main(String[] args) throws InterruptedException {
new MtThread().start();
Thread.sleep(2000);
new MtThread12().start();
new MtThread2().start();
Thread.sleep(2000);
}
static class MtThread extends Thread{
@Override
public void run() {
// TODO Auto-generated method stub
synchronized (TesA.class) {
try {
System.out.println("enter thread1...");
TesA.class.wait();
System.out.println("enter thread12222...");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
static class MtThread2 extends Thread{
@Override
public void run() {
// TODO Auto-generated method stub
synchronized (TesA.class) {
System.out.println("enter thread12...");
TesA.class.notify();
System.out.println("enter thread1211111...");
}
}
}
static class MtThread12 extends Thread{
@Override
public void run() {
// TODO Auto-generated method stub
synchronized (TesA.class) {
System.out.println("enter MtThread12...");
// TesA.class.notify();
System.out.println("enter MtThread12221111...");
}
}
}
}
wait 放弃synchronized 同步锁,
public class TesA {
public static void main(String[] args) throws InterruptedException {
new MtThread().start();
Thread.sleep(2000);
new MtThread12().start();
new MtThread2().start();
Thread.sleep(2000);
}
static class MtThread extends Thread{
@Override
public void run() {
// TODO Auto-generated method stub
synchronized (TesA.class) {
try {
System.out.println("enter thread1...");
TesA.class.wait();
System.out.println("enter thread12222...");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
static class MtThread2 extends Thread{
@Override
public void run() {
// TODO Auto-generated method stub
synchronized (TesA.class) {
System.out.println("enter thread12...");
TesA.class.notify();
System.out.println("enter thread1211111...");
}
}
}
static class MtThread12 extends Thread{
@Override
public void run() {
// TODO Auto-generated method stub
synchronized (TesA.class) {
System.out.println("enter MtThread12...");
// TesA.class.notify();
System.out.println("enter MtThread12221111...");
}
}
}
}
wait 放弃synchronized 同步锁,