生活随笔
收集整理的這篇文章主要介紹了
ConcurrentLinkedQueue
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
ConcurrentLinkedQueue
因?yàn)镃oncurrentLinkedQueue是線程序安全的并且是針對(duì)并發(fā)的
主類
Java代碼 ?
public?class?conn{??????public?static?void?main(String[]?args)?throws?Exception{??????????Queue<String>?queue=new?ConcurrentLinkedQueue<String>();??????????for(int?i=0;i<1000000;i++){?????????????queue.add(String.valueOf(i));??????????}??????????int?num=10;??????????for(int?i=0;i<num;i++){?????????????new?ThreadConn(queue);??????????}????????}??}??
線程類
Java代碼 ?
public?class?ThreadConn?implements?Runnable{??????Queue<String>?queue;??????public?ThreadConn(Queue<String>?queue){??????????this.queue=queue;??????????Thread?thread=new?Thread(this);??????????thread.start();??????}??????public?void?run(){??????????try{??????????????long?sd=new?Date().getTime();??????????????while(queue.poll()!=null){??????????????????????????????????????????}??????????????System.out.println?(sn-sd);??????????}catch(Exception?e){??????????????e.printStackTrace();??????????}??????}??}?
總結(jié)
以上是生活随笔為你收集整理的ConcurrentLinkedQueue的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。