Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Bastet Massri   on Jan 22 In Java Category.

  
Question Answered By: Pravat Jainukul   on Jan 22

But your explanation about the code,does not clear the main
problem comes to my mind. so i simplify the code  and i slip out the
codes nonsense not to discuss unrelated things. So my question  is
simple,

1-Why is the method  waitTest not waiting forever?..
2-Why is the method waitTest waiting forever if t.start() is
commented as it should be.

the real problem is question 1..in my opinion in both cases with
commented and without commented waitTest should wait forever.

Another point: Could you create a thread design that works in J2ME
MIDP1.0 or 2.0 profile that has a suspend method in it. currently
suspend is not included but you should able to build a thread class
that can suspend itself and resume itself. how can you do such a
thing without self notify&wake up .


class ThreadTest extends Thread {

public synchronized void waitTest(){
try{
wait();
System.out.println("waitTest has called..");
}catch(Exception ex){
ex.printStackTrace();
}

}
public void run(){
System.out.println("I'M DOING NOTHING& I'M NONSENSE :(");
}
}

public class Test{
public static void main(String arg[]){
ThreadTest t=new ThreadTest();
t.start(); // t.waitTest() never waits..
t.waitTest();

}

}

Share: 

 

This Question has 5 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on A challenging question about Threads&Synchronization Or get search suggestion and latest updates.