Original question:
https://coderanch.com/t/231957/threads/java/following-code-valid I created something similar:
The last question (when I was there last) in the top url is what the effect of creating two 'Threads' with one 'Runnable' would be. Seems to work fine.
(with the code commented out as mentioned in next posts) Why should you need two objects from 'Runnable' classes to create two 'Threads'? The
thread objects created are new seperate objects anyway.
Its not as if they contend for the one 'Runnable' object instance that was created, if I understand it correctly.
If that's true the 'Runnable' object is actually useless except for the creation of the 'Thread' objects.
public Thread(Runnable target)
Allocates a new Thread object. This constructor has the same effect as Thread(null, target, gname), where gname is a newly generated name. Automatically generated names are of the form "Thread-"+n, where n is an integer.
Parameters:
target - the object whose run method is called.
See Also:
Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)
[ September 19, 2002: Message edited by: Jim Crawford ]