• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

多线程可调用、可运行和螺纹(2021-11-22)


Recommended Posts

继承java.lang。线程的类,成为多线程的主体类(线程实现可运行)。通过覆写奔跑方法实现功能,通过调用开始启动。

常用可追捕的接口实现多线程(避免单继承的局限):覆写接口的奔跑方法,然后将接口对象作为线构造方法参数,用线的开始启动。

可运行的接口无返回值,需要使用请求即付的接口的呼叫方法返回值。使用请求即付的的继承、实现关系较复杂,可以参考下图和代码:可调用对象传给未来任务的构造方法;未来任务对象传给线启动线程,然后自己调用将来的接口的得到方法将值返回。

图片.png

请求即付的接口实例:

包线程演示

导入Java。util。并发。可赎回;

导入Java。util。并发。执行异常;

导入Java。util。并发。未来任务;

类神话故事实现可调用字符串{

@覆盖

公共字符串调用(){

for(int x=0;X5;x ) {

System.out.println('线程正在执行,x=' x);

}

'返回'返回值为字符串;

}

}

公共类主要{

公共静态void main(String[] args)引发异常{

FutureTaskString task=new FutureTaskString(new myth read());

新线程(任务)。start();

System.out.println('[线程返回值]'任务。get());

}

}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now