Threading in Java: How to lock an object?

前端 未结 7 709
长发绾君心
长发绾君心 2020-12-29 03:33

The following Function is executing in its own thread:

private void doSendData()
{
    try {

           //writeToFile(); // just a temporary location of a c         


        
7条回答
  •  暖寄归人
    2020-12-29 04:28

    In general when you have multi-threaded program in Java you need to lock the shared variable by using synchronized (key-word) then in anytime just one thread can access the shared memory.

提交回复
热议问题