`

Java__single process of file lock

阅读更多
import java.io.File;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;

public class OnlyYou
{
	//	返回Ture说明已经启动了
	public static boolean checkOnly(String name)
	{
		RandomAccessFile raf = null;
		FileChannel channel = null;
		FileLock lock = null;

		try
		{
			File file = new File(System.getProperty("java.io.tmpdir") + name + ".only");
			file.deleteOnExit();
			file.createNewFile();

			raf = new RandomAccessFile(file, "rw");
			channel = raf.getChannel();
			lock = channel.tryLock();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}

		if (lock == null) return true;
		else return false;
	}
}

分享到:
评论

相关推荐

    微软内部资料-SQL性能优化3

    Used to individually lock a single row within a table. Application A lock resource defined by an application. The lock manager knows nothing about the resource format. It simply compares the '...

    微软内部资料-SQL性能优化2

    A 32-bit process is normally limited to addressing 2 gigabytes (GB) of memory, or 3 GB if the system was booted using the /3G boot switch even if there is more physical memory available. By leveraging...

    强制PHP命令行脚本单进程运行的方法

    代码如下: /** * 保证单进程 * * @param string $processName 进程名 * @param string $pidFile 进程文件路径 * @return boolean 是否继续执行当前进程 */ function singleProcess($processName, $pidFile)...

    ( ap6181_sina33m_sc3817r验证通过_20170710_1608没有外层目录.7z

    # to observe dnsmasq.leases file for dhcp information of soft ap. chown dhcp system /data/misc/dhcp on post-fs-data mkdir /data/media 0770 media_rw media_rw # bluetooth MAC address programming ...

    BobBuilder_app

    Pages in a b+tree are usually implemented as a list or array of child pointers and so while finding and inserting a value is a O(log k) operation the process actually has to move children around in ...

    Windows蓝屏代码

    32. **0x0020 - STATUS_FILE_LOCK_CONFLICT** - **含义**:文件锁定冲突。 - **常见场景**:多个进程试图同时锁定同一个文件。 33. **0x0021 - STATUS_LOCK_NOT_GRANTED** - **含义**:未授予锁定。 - **常见...

    acpi控制笔记本风扇转速

    Moved all FADT-related functions to a new file, tbfadt.c. Eliminated the AcpiHwInitialize function - the FADT registers are now validated when the table is loaded. Added two new warnings during FADT ...

    UE(官方下载)

    You can use a combination of a script and tool to create a single file from multiple files. Sum Column/Selection in Column Mode This power tip demonstrates how to calculate the sum from a column of ...

    微软内部资料-SQL性能优化5

     If the table is a heap (in other words, it has no clustered index), the bookmark is a RID, which is an actual row locator in the form File#:Page#:Slot#. Finding Rows with a NC Index on a Heap ...

    UNIX环境高级编程英文第三版+源码

    4.25 Summary of File Access Per mission Bits 140 4.26 Summary 140 Chapter 5. Standard I/O Library 143 5.1 Introduction 143 5.2 Streams and FILE Objects 143 5.3 Standard Input, Standard Output, and ...

    EurekaLog_7.5.0.0_Enterprise

    4)....Added "--el_injectjcl", "--el_createjcl", and "--el_createdbg" command-line options for ecc32/emake to inject JEDI/JCL debug info, create .jdbg file, and create .dbg file (Microsoft debug format...

    Visual C++ 编程资源大全(英文源码 其它)

    in converts the text format (DOS or UNIX) of a file when it is saved in Visual Studio.(39KB)<END><br>78,devtruecolour.zip Use any colour in the Developer Studio IDE(49KB)<END><br>79,openvc_demo.zip...

    Practical Mod Perl

    Starting the Server in Single-Process Mode Section 5.3. Using kill to Control Processes Section 5.4. Using apachectl to Control the Server Section 5.5. Validating Server Configuration ...

    数位板压力测试

    The availability of drivers that support the features of the specification will simplify the process of developing Windows appli¬cation programs that in-corporate absolute coordinate input, and ...

    Radmin自动登录器v3.0-多国语言绿色版-Release1-20150615

    1、程序功能和使用环境介绍 2、程序操作方法介绍 3、登录信息文件RadminM.txt介绍 4、登录信息文件RadminM.txt的转换和编制 5、v3.0版新增解锁远程桌面功能 6、相关配置和多种语言支持介绍 ...

    Radmin自动登录器v3.0

    1、程序功能和使用环境介绍 2、程序操作方法介绍 3、登录信息文件RadminM.txt介绍 4、登录信息文件RadminM.txt的转换和编制 5、v3.0版新增解锁 远程桌面功能 6、相关配置和多种语言支持介绍 ...

    k7 SRIO参考例程

    immediatly by a single DWord SWrite packet. - SourceID not configureable for IReq port. - Version fixed : v5.1 - CR#473938 - Added ireq_src_id port to logical layer. All transmit source IDs ...

    sqlmap (懂的入)

    | Lock_tables_priv | enum | | max_connections | int | | max_questions | int | | max_updates | int | | max_user_connections | int | | Password | char | | Process_priv | enum | | References_priv ...

    ANSYS SpaceClaim 2016 User Guide

    Overall, **ANSYS SpaceClaim 2016** offers a robust set of tools and features designed to streamline the 3D modeling process. Whether you're a beginner looking to learn the basics or an experienced ...

Global site tag (gtag.js) - Google Analytics