package com.bjpowernode.demo02;
public class Test08 {
public static void main(String[] args) {
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
for( int i = 1; i <= 200; i++){
System.out.println( Thread.currentThread().getName() + "-->" + i);
}
}
});
t1.setPriority(10);
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
for( int i = 1; i <= 200; i++){
System.out.println( Thread.currentThread().getName() + "-->" + i);
}
}
});
t2.setPriority(1);
t2.start();
System.out.println( t1.getPriority());
System.out.println( t2.getPriority());
System.out.println( Thread.currentThread().getPriority());
for( int i = 1; i <= 200; i++){
System.out.println( Thread.currentThread().getName() + "-->" + i);
}
}
}
package com.bjpowernode.demo02;
public class Test09 {
public static void main(String[] args) throws InterruptedException {
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
for( int i = 1; i <= 100; i++){
System.out.println( Thread.currentThread().getName() + "-->" + i);
if (i % 10 == 0) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
});
t1.start();
Thread.sleep(2000);
}
}
package com.bjpowernode.demo02;
public class Test10 {
public static void main(String[] args) {
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
for( int i = 1; i <= 100; i++){
System.out.println( Thread.currentThread().getName() + "-->" + i);
if (i % 50 == 0) {
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
}
}
}
}
});
t1.start();
for( int i = 1; i <= 200; i++){
System.out.println( Thread.currentThread().getName() + "-->" + i);
}
System.out.println( t1.getState());
t1.interrupt();
}
}
package com.bjpowernode.demo02;
public class Test11 {
public static void main(String[] args) {
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
int i = 1;
while( !Thread.currentThread().isInterrupted() ){
System.out.println( Thread.currentThread().getName() + "-->" + i++);
}
System.out.println("t1 : " + Thread.currentThread().isInterrupted());
System.out.println("t1 : " + Thread.interrupted());
}
});
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
int i = 1;
while( !Thread.interrupted() ){
System.out.println( Thread.currentThread().getName() + "====>" + i++);
}
System.out.println("t2 : " + Thread.currentThread().isInterrupted());
System.out.println("t2 : " + Thread.interrupted());
}
});
t2.start();
for (int i = 1; i <= 50; i++) {
System.out.println(Thread.currentThread().getName() + "-->" + i);
}
t1.interrupt();
t2.interrupt();
}
}