package cn.itcast.heima2;
public class TraditionalThreadCommunication {
public static void main(String[] args) {
final Business business=new Business();
new Thread(
new Runnable() {
@Override
public void run() {
for(int i=1;i<=50;i++){
business.sub(i);
/*synchronized (ThaditionalThreadSynchronized.class) {
for (int j = 0; j <= 10; j++) {
System.out.println("sub thread sequece of"+i+",loop of"+j);
}
}*/
}
}
}
).start();
//主线程
for(int i=1;i<=50;i++){
business.main(i);
/*synchronized (ThaditionalThreadSynchronized.class) {
for (int j = 0; j <= 10; j++) {
System.out.println("main thread sequece of"+i+",loop of"+j);
}
}*/
}
}
}
class Business{
public synchronized void sub(int i){
for (int j = 0; j <= 10; j++) {
System.out.println("sub thread sequece of"+i+",loop of"+j);
}
}
public synchronized void main(int i){
for (int j = 0; j <= 10; j++) {
System.out.println("main thread sequece of"+i+",loop of"+j);
}
}
}
public class TraditionalThreadCommunication {
public static void main(String[] args) {
final Business business=new Business();
new Thread(
new Runnable() {
@Override
public void run() {
for(int i=1;i<=50;i++){
business.sub(i);
/*synchronized (ThaditionalThreadSynchronized.class) {
for (int j = 0; j <= 10; j++) {
System.out.println("sub thread sequece of"+i+",loop of"+j);
}
}*/
}
}
}
).start();
//主线程
for(int i=1;i<=50;i++){
business.main(i);
/*synchronized (ThaditionalThreadSynchronized.class) {
for (int j = 0; j <= 10; j++) {
System.out.println("main thread sequece of"+i+",loop of"+j);
}
}*/
}
}
}
class Business{
public synchronized void sub(int i){
for (int j = 0; j <= 10; j++) {
System.out.println("sub thread sequece of"+i+",loop of"+j);
}
}
public synchronized void main(int i){
for (int j = 0; j <= 10; j++) {
System.out.println("main thread sequece of"+i+",loop of"+j);
}
}
}