java多线程和线程池问题

一直是强势围观,从未发过贴。现在遇到一问题:同时用多个线程到处多个表的数据,各个表之间数据量未知,为了节省时间,使用多线程,由于本人属菜鸟级,所以对线程不是太了解,现用线程池解决这问题,不知这是否正确,或者是否有更优方法,或者此方法有哪些需要改进,忘各位大大不吝赐教,再此谢过。
代码如下


ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(1, 3, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(3),new ThreadPoolExecutor.CallerRunsPolicy());
for (String table : tables)
{
poolExecutor.execute(new ExportTask(entityName));
}

class ExportTask implements Runnable
{
ZipOutputStream zos;
String table;
public ExportTask(String table) throws FileNotFoundException
{
this.table =table;
zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(new File("packageDir", "abc.zip"))));
}

public void run()
{
// export the table data into file
export(table);
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值