/zookeeper2/data", "2182");Zkserver.startserver ();}
}Package my.zookeeperstudy;
public class ZKServer3 {
public static void Main (string[] args) throws Exception {Zkserver zkserver = new Zkserver ("3", "/tmp/zookeeper3/data", "2183");Zkserver.startserver ();}
}Distributed type Lock type Distributedlocker
Package my.zookeeperstudy.lock;
Import org.apache.zookeeper.*;
Import java.util.Collections;Import java.util.List;
public class Distributedlocker {Private Final zookeeper ZK;Private fin
For example, you might want to refer to the following implementation for a script that requires only sequential access to a resource, such as a disk file.
Copy Code code as follows:
#!/bin/bash
#
# File locking using Bash.
# ver 0.1.6
#
# Author:malundao (malundao@sina.com)
# date:2011-08-31
# ref:http://unix.derkeiler.com/newsgroups/comp.unix.shell/2005-09/0472.html
#
# Note:
# Shflock_cleanhook () is a user defined function to clean up user-specific sth.
#
#/path/to/lo
permanent blocking wait when the lock is occupied. The internallock code is as follows:
Private Boolean internallock (long time, timeunit unit) throws exception {// reentrant of the same thread is handled here. If the lock has been obtained, in this case, the number of acquire times is increased in the corresponding data structure, and the success thread currentthread = thread is returned directly. currentthread (); lockdata = threaddata. get (currentthread); If (lockdata! = NULL) {// re-enteri
Version dependent:
The sample code is as follows:
Package com.zk.lock;
Import Java.util.Random;
Import Java.util.concurrent.TimeUnit;
Import Org.apache.curator.framework.CuratorFramework;
Import Org.apache.curator.framework.recipes.locks.InterProcessMutex;
/** * Global Lock Simple Example */public class MyLock implements Runnable {private final String clientName;
Private final Interprocessmutex lock;
Public MyLock (Curatorframework client, String
zookeeper and requires the user to retry the policy. InternalLock (-1, null) is called in the code, and the parameter indicates permanent blocking wait when the lock is occupied. The internalLock code is as follows:
PrivatebooleaninternalLock (longtime, TimeUnitunit) throwsException
{
// Here, the reentrant of the same thread is processed. If the lock has been obtained, the acquire count is increased in the corresponding data structure, and success is returned directly.
ThreadcurrentThread = Th
The lock mechanism allows a specific shell script to run only one instance at a time. Specifically, the script instance for obtaining the lock can continue to execute the code in the critical section. If no lock instance is obtained, you can only wait.
For example, to require scripts to only access a certain resource in sequence, such as disk files, you can refer to the following implementation.
#!/bin/bash## file locking using bash.# ver 0.1.6## author : malundao ( malundao@sina.com )# date
Tomcat is mainly used as middleware in the architecture, and currently we use the LNMJ architecture, Tomcat to handle dynamic requests, processing speed, but the use of resources, this lazy cat, want to run fast will give a big fish, otherwise it will affect the host performanceThe following is a brief introduction to the optimization of the contentMiddleware level baseline detection According to CIS-TOMCAT7 's latest baseline standardsNote: Do not allow root login to be handled with caution, th
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.