Why can't i call Start() method twice on same thread object?
-
example code: public class MyThread extends Thread{ public void run(){ System.out.println("hi"); } } Thread mythread=new MyThread(); mythread.start(); mythread.start();// Exception why? Also Explain me What happens on calling Start() method? Note:don't say me it calls the run() method i know it Explain me Somewhat more Special things means internals details. Thanks!
-
Answer:
Solution- use a different object Eg- mythread.start() mythread2.start() Internal procssing- Calling start places the virtual CPU embodied in the thread into a runnable state, meaning it bcmz viable fr scheduling for execution by the JVM. In other words, by calling the start() you hav told the JVM to schedule your thread in the runnable threads queue. The nxt step automatically is to execute or run mythread. (Y do u want to re-request to place ur thread in the runnable state when the first call already does this for u. It is neither of a fruitful consequence nor semantically correct (poor compiler has to giv n error)) This request is generated by run(). (v say this as -the thread is in started state)Then when the thread reaches the start of the queue it starts running actually.
Nivedita Angel at Quora Visit the source
Related Q & A:
- Why can't I call on windows live messenger?Best solution by Yahoo! Answers
- Why can't I sign into Messenger but I can sign into Mail?Best solution by Yahoo! Answers
- Why can't my PSP start up?Best solution by Yahoo! Answers
- Why can't I access my Yahoo mail even though I can log into Yahoo?Best solution by Yahoo! Answers
- Why can't I receive picture messages but I can send them?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.