Differences in creating a thread?

I saw several different ways to create a new thread, but where I seem to have forgotten and cannot find many examples of it, and I would like to compare it with another way:

This one that I seemed to forget about, I'm not sure if Runnable requires it or not:

new Thread()
    {
        public void run()
        {
            System.out.println("running");
        }
    };

against.

new Thread(new Runnable()
    {
        public void run()
        {
            System.out.println("Running");
        }
    });

Differences? Disadvantages of benefits?

and when should I do an anonymous thread, and also when to run Runnable?

+3
source share
4 answers

I just saw you accepted the answer, after I, too, could not resist to give my answer here.

There is no subclass mark in your question Thread, so you need to do an extension Threador implementation here Runnable.

Thread , . this Thread. Runnable , .

run, , run Thread, target run , !

. , . .

!

+3

, anonymous classes, .

Thread t = new SubClassOfThread(); Thread t = new Thread(new ClassImplementingRunnable) ,

SubClassOfThread extends Thread , , Runnable, .

+1

, Runnable Thread.

, Thread. "". , run , , Runnable, , - Thread.

+1

, . Thread run (), Thread, Runnable run ().

, Thread ( ) run - . , , , .

+1

All Articles