今天小編給大家分享一下java中如何使用Runnable實(shí)現(xiàn)線程的相關(guān)知識點(diǎn),內(nèi)容詳細(xì),邏輯清晰,相信大部分人都還太了解這方面的知識,所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。
創(chuàng)新互聯(lián)于2013年創(chuàng)立,先為長治等服務(wù)建站,長治等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為長治企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
1、說明
需要實(shí)現(xiàn)Runnable接口的run()方法,使用newThread(newRunableClass()生成線程對象(RunnableClass已經(jīng)實(shí)現(xiàn)Runnable接口)時,線程對象的run()方法調(diào)用RunnableClass的run()。
2、實(shí)例
package com.java.test; public class ThreadTest { public static void main(String[] args) { // 線程的另一種實(shí)現(xiàn)方法,也可以使用匿名的內(nèi)部類 Thread threadtest1=new Thread((new ThreadTest1())); threadtest1.start(); Thread threadtest2=new Thread((new ThreadTest2())); threadtest2.start(); } } class ThreadTest1 implements Runnable { @Override public void run() { for (int i = 0; i < 100; ++i) { System.out.println("Hello: " + i); } } } class ThreadTest2 implements Runnable { @Override public void run() { for (int i = 0; i < 100; ++i) { System.out.println("Welcome: " + i); } } }
以上就是“java中如何使用Runnable實(shí)現(xiàn)線程”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會為大家更新不同的知識,如果還想學(xué)習(xí)更多的知識,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
新聞名稱:java中如何使用Runnable實(shí)現(xiàn)線程
網(wǎng)頁地址:http://aaarwkj.com/article30/iijspo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名、用戶體驗(yàn)、定制開發(fā)、App開發(fā)、品牌網(wǎng)站設(shè)計、面包屑導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)