eimmer
eimmer

Reputation: 319

Simple Thread Call

I've been reading up on how to use Thread in java, and I'm hoping someone can help me verify I'm using it correctly. I'm concerned that I should be calling .interrupt() or destroying the thread in some way.

I have a simple script that just hits my server to verify some data. My code:

Thread checkregister = new Thread(){
        @Override
        public void run(){
            checkSystem();
        }
    };
    checkregister.start();

Where checkSystem() posts the device id to a php script and waits for the response via HttpClient & HttpResponse. There isn't any looping so I don't think blocking is called for, but please let me know if I'm wrong.

Upvotes: 0

Views: 670

Answers (1)

LuxuryMode
LuxuryMode

Reputation: 33741

No need to destroy the Thread. The Thread is effectively taken out of the thread scheduler as soon as run() returns.

If for some reason you need a way to prematurely "end" the Thread, this is a bit more complicated and there's been a lot of discussion about the proper way to do it. Simple way though is to just call stop() on the Thread.

Upvotes: 2

Related Questions