“`” 有4种,分别是:

<ol><li>继承Thread类</li><li>实现Runnable接口</li><li>实现Callable接口<span style=""font-size: 1rem;"">通过FutureTask包装器来创建Thread线程</span></li><li><span style=""font-size: 1rem;"">通过线程池创建线程,使用线程池接口ExecutorService结合Callable、Future实现有返回结果的多线程。</span></li></ol>

<span style=""font-size: 1rem;"">前面两种【无返回值】原因:通过重写run方法,run方法的返回值是void,所以没有办法返回结果。</span>

<span style=""font-size: 1rem;"">后面两种【有返回值】原因:通过Callable接口,就要实现call方法,这个方法的返回值是Object,所以返回的结果可以放在Object对象中。</span>

<pre><code> "“`

Was this helpful?

0 / 0

发表回复 0

Your email address will not be published.