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();
}
}
相关文档:
熟悉C++的人对于两个字符串比较的代码一定很了解:
(string1==string2)
但在java中,这个代码即使在两个字符串完全相同的情况下也会返回false
Java中必须使用string1.equals(string2)来进行判断
补充
如果:
string s1=new String("Hello");
string s2=new String("Hello");
则(s1==s2)=false
如果:
s ......
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 ......
今天做Flex时碰到flex和java交互的乱码问题,使用HTTPService无论是从Flex端传到Java端,还是反过来都乱码。调查了半天,终于搞定了。
以下是解决方案:
1.Flex端传到Java端
Flex端:encodeURIComponent(comment.text)
使用encodeURIComponent把参数转换为 application/x-www ......
0
Java Web应用在ARM Linux平台上的实现
Posted in 硕博论文 at 十一月 12th, 2009 / No Comments »
王伟,周兰江,刘礼东,解云霄
(昆明理工大学信息工程与自动化学院,云南昆明650051)
1引言
随着网络信息技术的飞速发展,Web技术越来越多的用在控制领域,客户端只需连接以太网,取得访问权限,就可以访 ......