Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads

 
vendikonda sravan
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please explain the Fallowing line , "There are two threads acting on same instance",
Dose this mean like invoking start on same instance? like
Thread t=new Thread ();
t.start();
t.start();
I think we cann't say start() on same instance twice?


 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm no expert on threads, but as you say, calling start on the same thread
object doesn't look like a good idea.

I do--however, know a good place to begin to learn about threads. Try the following link:


JavaTutorial


G.

 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Real Java Tutorial
 
Geoff Jefferson
Ranch Hand
Posts: 102
 
Paul Clapham
Sheriff
Posts: 21124
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vendikonda sravan wrote:Please explain the Fallowing line , "There are two threads acting on same instance",
It could mean various things, depending on the context (which you didn't provide).
Dose this mean like invoking start on same instance?

That probably isn't one of the things it could mean. Again, looking at the context in which it was said would be a more useful idea.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think we need more context to know what is meant by "There are two threads acting on the same instance."

You cannot call start() more than once on the same Thread. You will get an IllegalThreadSTateException at runtime. As documented under Thread's start method, "It is never legal to start a thread more than once."

However, you can create a Runnable object (a class that implements Runnable), and use that instance in multiple Threads. For example...

But again, without more context, I don't know if this is what the original quote means.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15356
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Geoff: There is an edit button at the top right of your post, which you can click to edit your post.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49382
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper Young wrote:Geoff: There is an edit button . . .
Too late. I have already edited it.

Suggest you click ctrl-A ctrl-V when pasting URLs; that way you won't get htpp:// twice in the same URL
 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, thanks. It was time to leave work and I got a little sloppy.

cheeers.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic