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

Java 线程编程中的同步、重复、定时

(一)线程同步
实现生产者消费者问题来说明线程问题,举例如下所示:
/**
* 生产者消费者问题
*/
public class ProducerConsumer {

/**
* 主方法
*/
public static void main(String[] args) {
ProductBox pb = new ProductBox();
Producer p = new Producer(pb);
Consumer c = new Consumer(pb);

//根据消费者、生产者生成线程
Thread pThread = new Thread(p);
Thread cThread = new Thread(c);
pThread.setPriority(Thread.MAX_PRIORITY);

pThread.start();
cThread.start();
}

}

/**
* 产品对象
* @author johsnton678
*/
class Product {
int id;

public Product(int id) {
super();
this.id = id;
}

public String toString(){
return "Product:" + id;
}
}

/**
* 产品盒对象
* @author johnston678
*/
class ProductBox {

Product[] productbox = new Product[6];
int index = 0;
public ProductBox() {
super();
}

//存入方法,将产品存入产品盒
public synchronized void push(Product p) {
//判断产品是否超出产品盒的最大容量,如果超出中则等待
while (index == productbox.length) {
try {
this.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
this.notify();
productbox[index] = p;
index ++;
}

//取出操作
public synchronized Product pop() {
//如果产


相关文档:

Java中集合容器类List和Set的用法

List的用法
List包括List接口以及List接口的所有实现类。因为List接口实现了Collection接口,所以List接口拥有Collection接口提供的所有常用方法,又因为List是列表类型,所以List接口还提供了一些适合于自身的常用方法,如表1所示。
表1  List接口定义的常用方法及功能
从表1可以看出,List接口提供的适合于自身的 ......

通过Java或Jsp向数据库存取二进制图片


  1 MySQL存储大容量的二进制文件的格式是blob,其实除了图片还可以存别的
  2 要向数据库存储二进制的文件一定要把要存储的数据转换成二进制流
  废话就不多说了,大家看看代码很容易明白,先来看一个app程序,当然首先您要在数据库中先建立一个用于保存图片的表和相应的列,数据格式为blob
    package ......

Java初学者:软件设计 一个简单的图书管理软件

软件名称:图书管理工具
总体设计:
1.
命令行操作方式
2.
欢迎页面
---welcome to visit
software of book
management
                        
Now is ...
   & ......

java 根据两点经纬度来算距离

package com.njty.util;
public class Test {
  private static final double EARTH_RADIUS = 6378137;
  private static double rad(double d)
     {
        return d * Math.PI / 180.0;
     }
     ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号