View CompoundActionOnVector.java
package com.thomson.jcip.ch5.building; | |
import java.util.Vector; | |
/** | |
* 验证同步集合类存在的问题:在同步集合类上执行复合操作有可能出现问题 | |
* | |
* comes from the chapter5 of JCIP | |
* | |
* 同步集合类本身是线程安全的,所以将对象的状态委托给这些同步集合类来管理,就能保证线程安全性。但是还存在一种例外,如果在同一个集合类上执行复合操作,那么就会产生一些不符合预期的问题。 |
View updateUrlParameter.groovy
/** | |
* change the value of a specified query string in a url. | |
*/ | |
def updateUrlParameterValWithRegex(url, paraName, paraVal) { | |
assert url | |
def (path, paras) = url.tokenize('?') | |
println "the original url parameters:\n ${paras}" | |
def updatedUrl = paras.replaceFirst(/${paraName}=\w*/, "${paraName}=${paraVal}") | |
println "the updated url parameters:\n ${updatedUrl}" | |
"${path}${updatedUrl}" |
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
View StackQueue.java
package datastructure.stackqueue; | |
interface Stack { | |
void push(Object obj); | |
Object pop(); | |
boolean isEmpty(); | |
} | |
class ArrayStack implements Stack { | |
private Object[] theArray; |