多重启动判断之锁文件
public static void main(String[] args)
throws ClassNotFoundException
{
logger.info("Agent 正在启动");
logger.info("设置文件锁,保证单实例");
FileLock flock = null;
try
{
flock = new FileOutputStream("/opt/usp/agent/agent.lock").getChannel().tryLock();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e1)
{
e1.printStackTrace();
}
if (flock == null)
{
logger.info("Agent 已经运行,启动失败....");
System.exit(1);
}