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

后端 未结 6 639
无人共我
无人共我 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:22

    It sure is possible. Threading is the way to go here. In Java, you can launch a new thread like this

    Runnable backGroundRunnable = new Runnable() {
        public void run(){
             //Do something. Like call your function.
        }};
    Thread sampleThread = new Thread(backGroundRunnable);
    sampleThread.start();
    

    When you call start(), it launches a new thread. That thread will start running the run() function. When run() is complete, the thread terminates. Be careful, if you are calling from a swing app, then you need to use SwingUtil instead. Google that up, sir.

    Hope that works.

提交回复
热议问题