I want to see how Jboss creates/assign different threads from Thread pool once it finds previous thread busy.For that i tried to write down a code I hope making a thread sleep will make it busy and Jboss will create a new one. But it didnt work. I want my Test0 class to create 5 threads to execute run method of Test1 whenever it finds Test1 thread is busy in doing something.
public class Test1 extends Thread{
public Test1(){
System.out.println("T1 Constructor");
}
@Override
public void run() {
System.out.println("run from t1 "+ Thread.currentThread().getName());
try {
Thread.currentThread().sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
And I have Test0 class which will execute when jboss will start as follows
@Singleton
@Startup
public class Test0 {
private Test1 t1;
public Test0(){
}
@PostConstruct
public void starts(){
for (int i=0;i<5;i++){
t1=new Test1();
t1.start();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
Now in Test0 class I am manully creating 5 threads . How should i format the code to have Jboss create Thread from Thread pool?
Will it make any difference if i call t1.run() instead of t1.start() while running on servers? Because i know t1.run will not create a new thread but so this still holds same in case of servers as well?