开发者

can I execute a particular block of code inside a method via thread

can I execute a particular block of code inside a method via开发者_运维知识库 thread. As for example

Class A{
    public void execute(){

    /* some code where threading is not required*/
    /* block of code which need to execute via thread */

    }
}


class A {
    public void execute() {

        /* some code where threading is not required*/

        new Thread() {
            public void run() {
                /* block of code which need to execute via thread */
            }
        }.start();
    }
}


yup all you have to do is implement runnable, then call that meathod inside of run()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜