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

1 Answer

0 votes

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 Oct 10 in Full Stack Developer by rajeshsharma
0 votes
asked Mar 8, 2020 in Git Slack Integration by Hodge