This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GuardedObject<T> { | |
// 受保护的对象 | |
T obj; | |
final Lock lock = new ReentrantLock(); | |
final Condition done = lock.newCondition(); | |
final int timeout = 1; | |
T get(Predicate<T> p) { | |
lock.lock(); | |
try{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author luxz | |
* @date 2020/6/27-3:31 AM | |
* 如果执行乐观读操作期间,存在写操作,会把乐观读升级为悲观读锁 | |
*/ | |
public class Point { | |
private int x, y; | |
final StampedLock sl = new StampedLock(); | |
int distanceFromOrigin() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CacheData { | |
Object data; | |
volatile boolean isCacheValid; | |
final ReadWriteLock rwl = new ReentrantReadWriteLock(); | |
// 读锁 | |
final Lock r = rwl.readLock(); | |
// 写锁 | |
final Lock w = rwl.writeLock(); | |
void processCacheData() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class VolatileExample { | |
int x = 0; | |
volatile boolean v = false; | |
void writer() { | |
x = 42; | |
v = true; | |
} | |
void reader() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LinkedStack<T> { | |
private static class Node<U> { | |
U item; | |
Node<U> next; | |
Node(){ | |
item = null; | |
next = null; | |
} | |
Node(U item, Node<U> next){ | |
this.item = item; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package soundsystem; | |
import java.util.HashMap; | |
import java.util.Map; | |
import org.aspectj.lang.annotation.Aspect; | |
import org.aspectj.lang.annotation.Before; | |
import org.aspectj.lang.annotation.Pointcut; | |
@Aspect | |
public class TrackCounter{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.searover.hctest; | |
import org.apache.commons.lang.time.StopWatch; | |
import org.apache.http.HttpEntity; | |
import org.apache.http.client.ClientProtocolException; | |
import org.apache.http.client.HttpClient; | |
import org.apache.http.client.methods.CloseableHttpResponse; | |
import org.apache.http.client.methods.HttpGet; | |
import org.apache.http.impl.client.CloseableHttpClient; | |
import org.apache.http.impl.client.DefaultHttpClient; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.anchnet.ddos.report.utils; | |
import com.anchnet.ddos.report.beans.MessagePack; | |
import org.apache.commons.httpclient.HttpClient; | |
import org.apache.commons.httpclient.HttpMethod; | |
import org.apache.commons.httpclient.NameValuePair; | |
import org.apache.commons.httpclient.methods.GetMethod; | |
import org.apache.commons.httpclient.methods.PostMethod; | |
import java.io.IOException; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Container for an array of values that were retrieved with | |
* {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)} | |
* or {@link Resources#obtainAttributes}. Be | |
* sure to call {@link #recycle} when done with them. | |
* | |
* The indices used to retrieve values from this structure correspond to | |
* the positions of the attributes given to obtainStyledAttributes. | |
*/ | |
public class TypedArray { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public TypedArray obtainStyledAttributes(AttributeSet set, | |
int[] attrs, int defStyleAttr, int defStyleRes) { | |
final int len = attrs.length; | |
final TypedArray array = TypedArray.obtain(Resources.this, len); | |
// other code ..... | |
return array; | |
} |
NewerOlder