1. 安装编译需要的库和头文件
yum install gcc -y
yum install kernel sources -y
yum install kernel-devel -y
2. 安装VirtualBox增强功能
3. 重新启动系统
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 {
Listthreads = new ArrayList ();
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 {
Listthreads = new ArrayList ();
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);
}
}