import java.io.FileInputStream;
public class TTT {
public static void main(String[] args) throws Exception {
for (int i = 0; i < 10; i++) {
final String threadId = "thread_" + i;
Thread thread = new Thread(new Runnable() {
public void run() {
System.out.println(threadId + " started!");
try {
FileInputStream fis = new FileInputStream("/opt/test.log");
Thread.sleep(60 * 1000);
} catch (Exception ex) {
ex.printStackTrace();
}
System.out.println(threadId + " stopped!");
}
});
thread.start();
}
Thread.sleep(10 * 60 * 1000);
}
}
$ /usr/sbin/lsof -p `ps -ef | grep java | grep TTT | awk '{print $2}'` | grep "test.log"
java 21562 fkong 3r REG 253,0 0 35471424 /opt/test.log
java 21562 fkong 4r REG 253,0 0 35471424 /opt/test.log
java 21562 fkong 5r REG 253,0 0 35471424 /opt/test.log
java 21562 fkong 6r REG 253,0 0 35471424 /opt/test.log
java 21562 fkong 7r REG 253,0 0 35471424 /opt/test.log
java 21562 fkong 8r REG 253,0 0 35471424 /opt/test.log
java 21562 fkong 9r REG 253,0 0 35471424 /opt/test.log
java 21562 fkong 10r REG 253,0 0 35471424 /opt/test.log
java 21562 fkong 11r REG 253,0 0 35471424 /opt/test.log
java 21562 fkong 12r REG 253,0 0 35471424 /opt/test.log
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;
public class TTT {
public static void main(String[] args) throws Exception {
List<Thread> threads = new ArrayList<Thread>();
for (int i = 0; i < 10; i++) {
final String threadId = "thread_" + i;
Thread thread = new Thread(new Runnable() {
public void run() {
System.out.println(threadId + " started!");
try {
FileInputStream fis = new FileInputStream("/opt/test.log");
Thread.sleep(60 * 1000);
} catch (Exception ex) {
ex.printStackTrace();
}
System.out.println(threadId + " stopped!");
}
});
thread.start();
threads.add(thread);
}
Thread.sleep(2 * 60 * 1000);
for (Thread thread : threads) {
thread = null;
}
System.out.println("Clean up threads!");
Thread.sleep(10 * 60 * 1000);
}
}
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;
public class TTT {
public static void main(String[] args) throws Exception {
List<Thread> threads = new ArrayList<Thread>();
for (int i = 0; i < 10; i++) {
final String threadId = "thread_" + i;
Thread thread = new Thread(new Runnable() {
public void run() {
System.out.println(threadId + " started!");
try {
FileInputStream fis = new FileInputStream("/opt/test.log");
Thread.sleep(60 * 1000);
} catch (Exception ex) {
ex.printStackTrace();
}
System.out.println(threadId + " stopped!");
}
});
thread.start();
threads.add(thread);
}
Thread.sleep(2 * 60 * 1000);
for (Thread thread : threads) {
thread = null;
}
System.out.println("Clean up threads!");
System.gc();
System.gc();
System.gc();
System.out.println("Finished GC!");
Thread.sleep(10 * 60 * 1000);
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有