Solved

thread ID setting

Posted on 2014-02-07
6
502 Views
Last Modified: 2014-02-13
Hi,

I am working on below example
http://www.avajava.com/tutorials/lessons/how-do-i-identify-a-thread.html

I have not seen author setting thread ID anywhere. Where it is getting set.


i see output as below

RunnableJob is being run by thread1 (9)
RunnableJob is being run by Thread-1 (11)
Main thread: main(1)
RunnableJob is being run by thread2 (10)

which line is printing below output
RunnableJob is being run by Thread-1 (11)
please advise
Any links resources ideas highly appreciated. Thanks in advance
0
Comment
Question by:gudii9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 14

Accepted Solution

by:
CPColin earned 250 total points
ID: 39843344
It's thread3, with the default thread name. The Javadocs for the Thread class mention that:

If a name is not specified when a thread is created, a new name is generated for it.

The end of the tutorial you linked mentions that "Thread-1" is the default name, too.
0
 
LVL 28

Assisted Solution

by:dpearson
dpearson earned 250 total points
ID: 39843723
Specifically it's being set here in the constructor for Thread:

    /**
     * Allocates a new {@code Thread} object. This constructor has the same
     * effect as {@linkplain #Thread(ThreadGroup,Runnable,String) Thread}
     * {@code (null, null, gname)}, where {@code gname} is a newly generated
     * name. Automatically generated names are of the form
     * {@code "Thread-"+}<i>n</i>, where <i>n</i> is an integer.
     */
    public Thread() {
        init(null, null, "Thread-" + nextThreadNum(), 0);
    }
0
 
LVL 7

Author Comment

by:gudii9
ID: 39851100
It's thread3, with the default thread name


which is Default thread?
I see main thread and thread1 and thread2 in the code. Where from default thread is coming in this example.

Specifically it's being set here in the constructor for Thread:


How to check which specific constructor it is setting from
Please advise
0
Stressed Out?

Watch some penguins on the livecam!

 
LVL 14

Expert Comment

by:CPColin
ID: 39851107
which is Default thread?

When I said "default thread name," I meant "the name that is assigned to threads, by default." There is no such thing as a "default thread."
0
 
LVL 7

Author Comment

by:gudii9
ID: 39851151
Default thread is below thread in the code right?
Thread thread3 = new Thread(runnableJob);
            thread3.start();


Please advise
0
 
LVL 14

Expert Comment

by:CPColin
ID: 39851154
There is no such thing as a "default thread."

In that code, that thread is being assigned a default name, because you didn't specify one. That's what dpearson and I were talking about on Friday.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question