File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Can anybody tell me How to use getState() method with an thread object. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Can anybody tell me How to use getState() method with an thread object." Watch "Can anybody tell me How to use getState() method with an thread object." New topic
Author

Can anybody tell me How to use getState() method with an thread object.

Ravi Kumar
Greenhorn

Joined: Feb 12, 2007
Posts: 6
//Creates Thread object.
Thread t1 = new Thread(tg1,obj1);
//Starts Thread
t1.start();
t1.getState();


This code is not working as getState() returns an enum type i.e. Thread.state
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Assuming you are using Java 5 or later, your code should compile and run. The getState() does nothing useful, though, because you are discarding the return value. You need to assign it to something and use it.

If you are using Java 1.4 or earlier, you cannot use getState() because there's no such method.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
vu lee
Ranch Hand

Joined: Apr 19, 2005
Posts: 189
I think you are asking to see the state of a thread.
System.out.println(t1.getState());
you'll see one of the followings:
* NEW
A thread that has not yet started is in this state.
* RUNNABLE
A thread executing in the Java virtual machine is in this state.
* BLOCKED
A thread that is blocked waiting for a monitor lock is in this state.
* WAITING
A thread that is waiting indefinitely for another thread to perform a particular action is in this state.
* TIMED_WAITING
A thread that is waiting for another thread to perform an action for up to a specified waiting time is in this state.
* TERMINATED
A thread that has exited is in this state.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can anybody tell me How to use getState() method with an thread object.