alcuni test su synchronized e singleton
This commit is contained in:
56
threads_test/test_1_start.java
Normal file
56
threads_test/test_1_start.java
Normal file
@@ -0,0 +1,56 @@
|
||||
package threads_test;
|
||||
|
||||
/**
|
||||
* Created by Giovanni on 04/10/2014.
|
||||
*/
|
||||
public class test_1_start {
|
||||
|
||||
public static class xthread implements Runnable{
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
for (int i = 0;i<10;i++) {
|
||||
|
||||
System.out.println("alee");
|
||||
Thread.currentThread().sleep(1000);
|
||||
|
||||
}
|
||||
}catch (InterruptedException e) {
|
||||
|
||||
System.out.println("manno acciso");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void main (String[] args){
|
||||
|
||||
try {
|
||||
|
||||
xthread a = new xthread();
|
||||
Thread t = new Thread(a);
|
||||
t.start();
|
||||
|
||||
t.join(5000);
|
||||
if (t.isAlive()) {
|
||||
t.interrupt();
|
||||
t.join();
|
||||
System.out.println("killato e uscito");
|
||||
}else {
|
||||
System.out.println("uscito");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
catch (InterruptedException e){
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user