How do you stop a thread in java?



How do you stop a thread in java?..

Answer / Pushpendra Arya

To stop a thread in Java, you can use one of the following methods: (1) Call the interrupt() method on the Thread object. This sets the interrupted status flag for the thread and can be checked using the interrupted() method. (2) Have the thread check a volatile boolean flag periodically and terminate itself when the flag is set to true.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

What is parameters example?

1 Answers  


Why hashcode is used in java?

1 Answers  


can java object be locked down for exclusive use by a given thread? Or what happens when a thread cannot acquire a lock on an object? : Java thread

1 Answers  


Difference between the String and StringBuffer classes?

3 Answers  


Is linked list a linear or non-linear data structure?

1 Answers   Akamai Technologies,


Where will it be used?

1 Answers  


What is set in java?

1 Answers  


In how many ways we can create threads in java?

1 Answers  


What are the three parts of a lambda expression?

1 Answers  


How do you find the maximum number from an array without comparing and sorting?

1 Answers   BlackRock,


What are the advantages of java over cpp?

1 Answers  


what is Inheritense

3 Answers   Tech Mahindra,


Categories