易截截图软件、单文件、免安装、纯绿色、仅160KB

Java SE 多线程 线程通信

package thread;
class QQ{
 private String name;
 private String sex;
 boolean flag=false;
 public synchronized void put(String name,String sex){
  if(flag)
   try {
    wait();
   } catch (InterruptedException e1) {
    e1.printStackTrace();
   }
  this.name=name;
  try {
   Thread.sleep(10);
  } catch (InterruptedException e) {
   e.printStackTrace();
  }
  this.sex=sex;
  flag=true;
  notify();
 }
 public synchronized void get(){
  if(!flag)
   try {
    wait();
   } catch (InterruptedException e) {
    e.printStackTrace();
   }
  System.out.println(name +"----------->"+sex);
  flag=false;
  notify();
 }
}
class Producer1 implements Runnable{
 QQ qq=null;
 public Producer1(QQ qq){
  this.qq=qq;
 }
 public void run() {
  int i=0;
  while(true){
   if(i==0){
    qq.put("zxx", "nan");
   }else{
    qq.put("cq", "nv");
   }
    i=(i+1)%2;
  }
 }
 
}
class Consumer1 implements Runnable{
 QQ qq=null;
 public Consumer1(QQ qq){
  this.qq=qq;
 }
 public void run() {
  while(true){
   qq.get();
  }
 }
 
}
public class ThreadCommunciation {
 public static void main(String[] args) {
  QQ qq=new QQ();
  new Thread(new Producer1(qq )).start();
  new Thread(new Consumer1(qq)).start();
 }
}


相关文档:

Java NIO API详解

 
Java NIO API详解
在JDK
1.4以前,Java的IO操作集中在java.io这个包中,是基于流的阻塞(blocking)API。对于大多数应用来说,这样的API使用很方
便,然而,一些对性能要求较高的应用,尤其是服务端应用,往往需要一个更为有效的方式来处理IO。从JDK 1.4起,NIO
API作为一个基于缓冲区,并能提供非阻塞(non-blo ......

用java抓取cnproxy代理服务器地址

package org.mingyuan.fetcher;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
i ......

Java中字符串比较的注意点

熟悉C++的人对于两个字符串比较的代码一定很了解:
(string1==string2)
但在java中,这个代码即使在两个字符串完全相同的情况下也会返回false
Java中必须使用string1.equals(string2)来进行判断
补充
如果:
string s1=new String("Hello");
string s2=new String("Hello");
则(s1==s2)=false
如果:
s ......

Java SE 多线程

package thread;
class TestThread extends Thread {
 public void run(){
  while(true){
   System.out.println(Thread.currentThread().getName());
  }
 }
}
public class ThreadDemo {
 /**
  * @param args
  */
 public static void ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号