首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

关于solaris下进程能打开的最大文件数的有关问题

2011-11-21 
关于solaris下进程能打开的最大文件数的问题用ulimit -n 命令查看,结果是256, 这说明进程能打开的最大文件

关于solaris下进程能打开的最大文件数的问题
用ulimit -n 命令查看,结果是256, 这说明进程能打开的最大文件数不超过256个 
但下面的java程序却能成功打开10000多个, 这是什么原因? 

import java.io.*; 

public class openfile{ 
  public static void main(String[] args) 
  { 
  PrintWriter[] bw = new PrintWriter[15000]; 

  try{ 
  for (int i=0; i < bw.length; i++) 
  { 
  bw[i] = new PrintWriter(new BufferedWriter(new FileWriter("test"+i))); 
  bw[i].println("Hello World! " + i); 
  bw[i].close(); 
  }  
   
  //这个循环可以成功地打开15000个文件  
  for (int i=0; i < bw.length; i++) 
  { 
  BufferedReader br = new BufferedReader(new FileReader("test" + i)); 
  String str = br.readLine(); 
  System.out.println("read file test" + i + " : " + str); 
   
  try{ 
  if (i % 256 == 0) Thread.sleep(1000); 
  }catch(Exception e){} 
  } 


  String s = "test0"; 
  File f = new File(s); 
  if (f.exists()) 
  { 
  Process pro = Runtime.getRuntime().exec("/opt/swe/bin/gzip " + "test0"); 
  pro.waitFor(); 

  System.out.println("exit value: " + pro.exitValue()); 
  } 
  else 
  System.out.println("file not exsit"); 

  } 
  catch(Exception e) 
  { 
  System.out.println("exception! " + e.getMessage()); 
  } 

  System.out.println("Bye..."); 
  } 



[解决办法]
java有 自动回收机制,可以自动释放内存空间
[解决办法]
UP

[解决办法]
看下java垃圾回收机制

热点排行