wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Threads" Watch "Threads" New topic
Author

Threads

vendikonda sravan
Ranch Hand

Joined: May 09, 2010
Posts: 38
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

Joined: Apr 09, 2009
Posts: 102
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

Joined: Apr 09, 2009
Posts: 102
The Real Java Tutorial
Geoff Jefferson
Ranch Hand

Joined: Apr 09, 2009
Posts: 102
I know this will work.


http://download-llnw.oracle.com/javase/tutorial/essential/concurrency/runthread.html
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Aug 31, 2004
Posts: 11343

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.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14194
    
  20

Geoff: There is an edit button at the top right of your post, which you can click to edit your post.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39084
    
  23
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

Joined: Apr 09, 2009
Posts: 102
Ok, thanks. It was time to leave work and I got a little sloppy.

cheeers.

 
GeeCON Prague 2014
 
subject: Threads