0 votes
in JAVA by
Can you tell us at least 5 best practice you use while using threads in Java?

1 Answer

0 votes
by

This is similar to the previous question and you can use the answer given there. Particularly with thread, you should:

a) name your thread

b) keep your task and thread separate, use Runnable or Callable with thread pool executor.

c) use thread pool

d) use volatile to indicate compiler about ordering, visibility, and atomicity.

e) avoid thread local variable because incorrect use of ThreadLocal class in Java can create a memory leak.

Look there are many best practices and I give extra points to the developer which bring something new, something even I don't know. I make sure to ask this question to Java developers of 8 to 10 years of experience just to gauge his hands on experience and knowledge.

Related questions

0 votes
asked Jun 3, 2023 in Python Flask by AdilsonLima
+2 votes
asked Feb 8, 2020 in JAVA by rahuljain1
...