Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #8670
| Date | 2011-10-09 20:37 -0700 |
|---|---|
| From | Patricia Shanahan <pats@acm.org> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: java Thread class |
| References | <319384c2-13c3-45f1-a9be-2be669a2204b@r8g2000prh.googlegroups.com> |
| Message-ID | <uY6dnTXgXdrz9Q_TnZ2dnUVZ_rednZ2d@earthlink.com> (permalink) |
On 10/9/2011 8:07 PM, 光 署 wrote:
> hi all, I have a Thread named r1 , why I can not write "
> r1.start();r1.start();". when I write "r1.start(); r1.start();" there
> was an error that "IllegalThreadStateException".
>
> r1.run(){
> public void run(){
> System.out.println("name" + super.getName() + "---->" +
> super.getI());
> }
> }
In general, it is better to use a Runnable rather than extending Thread.
You cannot start a Thread instance more than once. You can create
several Thread instances using the same Runnable, and start each Thread
once.
You may find you need a separate Runnable for each Thread, so that
they do not share fields, when you code the actual work, rather than a
simple print-out.
Patricia
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar
java Thread class 光 署 <shuguang008@gmail.com> - 2011-10-09 20:07 -0700 Re: java Thread class Knute Johnson <nospam@knutejohnson.com> - 2011-10-09 20:20 -0700 Re: java Thread class Patricia Shanahan <pats@acm.org> - 2011-10-09 20:37 -0700
csiph-web