• Post Reply Bookmark Topic Watch Topic
  • New Topic

getState  RSS feed

 
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Thread.State state = Thread.currentThread().getState();

Getstate returns the thread's state.But Thread.State,..........? Thread is a class.Is Thread.State class too?

It is strange for me.
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What did you find when you checked the API for Thread?
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Is State an enum variable?
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May someone make it clear please?
 
Sheriff
Posts: 22846
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you scroll down through the API page for the java.lang package you'll find a section entitled "Enum Summary". In that section you'll find an entry for an enum named Thread.State. Have a look there and if you still find something unclear, come back and tell us what it is that you find unclear.
 
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I presume the thread states in the enum correspond to those which the thread can occupy, which I expect you already know about. They should be in the Java Tutorials, however.
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in method summary section it is written Thread.State is the name of a method. Right?

http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.State.htm

May you give me a simple example that return enum?l
 
Paul Clapham
Sheriff
Posts: 22846
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abalfazl hossein wrote:in method summary section it is written Thread.State is the name of a method. Right?


No. There are two methods in the Method Summary section. One of them is called "valueOf" and returns a Thread.State object. The other one is called "values" and returns an array of Thread.State objects.
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
State in "Thread.state", Is the name of a method?

May you give me a simple example of a method that return an enum?
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it is not the name of a method, it's the name of an enum, as you can clearly see in the API documentation.

If you have trouble understanding what enum types are, then have a look at the tutorial: Enum Types
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May you give me a simple example of a method that return an enum?
 
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here:



 
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming that you have worked through the tutorial Jesper linked to as well as the API docs, you should be able to tell which values Thread.State can take. If you know that, and assuming that you have written methods that return objects before, are you now able to write a method that returns an enum?

Or, to put it the other way around, tell us why you think returning an enum state is different from returning some other object.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!