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

java在for循环中使用concurrent包进行多线程编程

  最近在做接口的时候总是遇到一个for语句中 每次循环会涉及很多资源,包括 ftp io db,总想用现场来控制太.找到一篇文章  http://daoger.javaeye.com/blog/142485 写的不错.自己写了2个demo
1. 主线程不等待
 public class CopyOfTestThreadPool {
 public static void main(String args[]) throws InterruptedException {
  // only two threads
  ExecutorService exec = Executors.newFixedThreadPool(20);
  List<Long> list = new ArrayList<Long>();
  for(int index = 0; index < 1000000; index++){
   list.add(System.nanoTime());
  }
  
  long start = System.currentTimeMillis();
  for (Long long1 : list) {
   final Long l = long1;
   exec.execute(new Runnable(){
    public void run() {
     System.out.println(l);
     try {
      Thread.sleep(5000);
     } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
     }
     
    }});
  }
  // must shutdown
  exec.shutdown();
   long end = System.currentTimeMillis();
   System.out.print("共计用时 ");
   System.out.println(end  - start);
 }
}
2 主线程会等待
public class TestCountDownLatch {
 public static void main(String[] args) throws InterruptedException {
  long start = System.currentTimeMillis();
  // 开始的倒数锁
  final CountDownLatch begin = new CountDownLatch(1);
  // 结束的倒数锁
  final CountDownLatch end = new CountDownLatch(10000);
  // 十名选手
  final ExecutorService exec = Executors.newFixedThrea


相关文档:

sql 2005 存储过程分页 java 代码

 create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',         
@pagesize int output,--每页显示记录条数
@currentpage int output,--第几页
@orderid nvarchar(50),--主键排序
@sort int,--排序方式,1表示升序,0表示降序排列 ......

java 绝对路径工具类

在程中我们常取一些资源的绝对径,下面给出一个简单方便的工具类来帮助我们轻松的找到我想的资源。(适用于CS/BS应用)
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

/** *//**
* @author <a href="mailto:maryang@live.cn" mce_hre ......

think in java ch6

-------------------------------------------------
本教程由yyc,spirit整理
------------------------------------------------- 第6章 类再生
“Java引人注目的一项特性是代码的重复使用或者再生。但最具革命意义的是,除代码的复制和修改以外,我们还能做多得多的其他事情。”
在象C那样的 ......

JAVA中方法和变量在继承中的覆盖和隐藏

http://renyanwei.javaeye.com/blog/258304
我们知道,在JAVA中,子类可以继承父类,如果子类声明的方法与父类有重名的情况怎么办,大伙儿都知道要是重写,但是实际上这又分为两种情况,就是方法和变量在继承时的覆盖和隐藏问题,这些概念性的东西看似无聊,但是在面试或者是SCJP认证题中围绕这些是会经常碰到的,所以这里 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号