Call a function without waiting for it

前端 未结 6 1525
粉色の甜心
粉色の甜心 2021-02-02 00:59

Hi I was wondering if there was a way of calling a function/method (preferably in Python or Java) and continue execution without waiting for it.

Example:



        
6条回答
  •  轮回少年
    2021-02-02 01:39

    In Java, there's a standard idiom: create a thread and run it:

    new Thread() {
        @Override
        public void run() {
            callMyFunction();
        }
    }.start();
    

    Or you can create a Runnable and pass it to the thread:

    Runnable caller = new Runnable() {
        @Override
        public void run() {
            callMyFunction();
        }
    }
    
    new Thread(caller).start();
    

提交回复
热议问题