thread ID setting

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
LVL 7
gudii9Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
CPColinConnect With a Mentor Senior Java ArchitectCommented:
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
 
dpearsonConnect With a Mentor Commented:
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
 
gudii9Author Commented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
CPColinSenior Java ArchitectCommented:
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
 
gudii9Author Commented:
Default thread is below thread in the code right?
Thread thread3 = new Thread(runnableJob);
            thread3.start();


Please advise
0
 
CPColinSenior Java ArchitectCommented:
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
All Courses

From novice to tech pro — start learning today.