=10")}publicstaticvoidmain(String[]args){Clientc=newClient()Servers=newServer(c)c.start()s.start()}}classClientextendsThread{VectorqueuepublicClient(){this.queue=newVector()}publicvoidrun(){while(true){if(!(queue.size()==0)){processNextElement()}}}privatevoidprocessNextElement(){Objectnext=queue.elementAt(0)queue.removeElementAt(0)System.out.println(next)-publicclassServerextendsThread{ClientclientintcounterpublicServer(Client_client){this.client=_clientthis.counter=0}publicvoidrun(){while(counterlt;10){this.client.queue.addElement(newInteger(counter))counter++}thrownewRuntimeException("countergt;=10")}p-IMDN开发者社群-imdn.cn"> =10")}publicstaticvoidmain(String[]args){Clientc=newClient()Servers=newServer(c)c.start()s.start()}}classClientextendsThread{VectorqueuepublicClient(){this.queue=newVector()}publicvoidrun(){while(true){if(!(queue.size()==0)){processNextElement()}}}privatevoidprocessNextElement(){Objectnext=queue.elementAt(0)queue.removeElementAt(0)System.out.println(next)-publicclassServerextendsThread{ClientclientintcounterpublicServer(Client_client){this.client=_clientthis.counter=0}publicvoidrun(){while(counterlt;10){this.client.queue.addElement(newInteger(counter))counter++}thrownewRuntimeException("countergt;=10")}p - IMDN开发者社群-imdn.cn">
登录
首页 » Static control » public class Server extends Thread { Client client int counter public Server(Cli...

public class Server extends Thread { Client client int counter public Server(Cli...

于 2022-02-21 发布 文件大小:1.08 kB
0 68
下载积分: 2 下载次数: 1

代码说明:

public class Server extends Thread { Client client int counter public Server(Client _client) { this.client = _client this.counter = 0 } public void run() { while (counter < 10) { this.client.queue.addElement(new Integer(counter)) counter++ } throw new RuntimeException("counter >= 10") } public static void main(String[] args) { Client c = new Client() Server s = new Server(c) c.start() s.start() } } class Client extends Thread { Vector queue public Client() { this.queue = new Vector() } public void run() { while (true) { if (! (queue.size() == 0)) { processNextElement() } } } private void processNextElement() { Object next = queue.elementAt(0) queue.removeElementAt(0) System.out.println(next)-public class Server extends Thread { Client client int counter public Server(Client _client) { this.client = _client this.counter = 0 } public void run() { while (counter lt; 10) { this.client.queue.addElement(new Integer(counter)) counter++ } throw new RuntimeException("counter gt;= 10") } p

下载说明:请别用迅雷下载,失败请重下,重下不扣分!

发表评论

0 个回复

  • 696524资源总数
  • 103971会员总数
  • 70今日下载