How to make calling a Method as a background process in java

后端 未结 6 691
无人共我
无人共我 2021-01-16 06:50

In my application , I have this logic when the user logins , it will call the below method , with all the symbols the user owns .

public void sendSymbol(Stri         


        
6条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-16 07:21

    There is no really simple solution. Basically you need another thread which runs the method, but you also have to care about synchronization and thread-safety.

    new Thread(new Runnable() {
    
    public void run() {
         sendSymbol(String commaDelimitedSymbols);
        }
    }).start();
    

    Maybe a better way would be to use Executors

    But you will need to case about thread-safety. This is not really a simple task.

提交回复
热议问题