/**
* A ThreadContext provides a means of binding and unbinding objects to the
* current thread based on key/value pairs.
*
*
An internal {@link java.util.HashMap} is used to maintain the key/value pairs
* for each thread.
*
*
If the desired behavior is to ensure that bound data is not shared across
* threads in a pooled or reusable threaded environment, the application (or more likely a framework) must
* bind and remove any necessary values at the beginning and end of stack
* execution, respectively (i.e. individually explicitly or all via the clear method).
*
* @see #remove()
* @since 0.1
*/
public abstract class ThreadContext {
/**
* Returns the ThreadLocal Map. This Map is used internally to bind objects
* to the current thread by storing each object under a unique key.
*
* @return the map of bound resources
*/
public static Map
/**
* Allows a caller to explicitly set the entire resource map. This operation overwrites everything that existed
* previously in the ThreadContext - if you need to retain what was on the thread prior to calling this method,
* call the {@link #getResources()} method, which will give you the existing state.
*
* @param newResources the resources to replace the existing {@link #getResources() resources}.
* @since 1.0
*/
public static void setResources(Map newResources) {
if (CollectionUtils.isEmpty(newResources)) {
return;
}
ensureResourcesInitialized();
resources.get().clear();
resources.get().putAll(newResources);
}
/**
* Returns the value bound in the {@code ThreadContext} under the specified {@code key}, or {@code null} if there
* is no value for that {@code key}.
*
* @param key the map key to use to lookup the value
* @return the value bound in the {@code ThreadContext} under the specified {@code key}, or {@code null} if there
* is no value for that {@code key}.
* @since 1.0
*/
private static Object getValue(Object key) {
Map perThreadResources = resources.get();
return perThreadResources != null ? perThreadResources.get(key) : null;
}
/**
* Returns the object for the specified key that is bound to
* the current thread.
*
* @param key the key that identifies the value to return
* @return the object keyed by key or null if
* no value exists for the specified key
*/
public static Object get(Object key) {
if (log.isTraceEnabled()) {
String msg = "get() - in thread [" + Thread.currentThread().getName() + "]";
log.trace(msg);
}
Object value = getValue(key);
if ((value != null) && log.isTraceEnabled()) {
String msg = "Retrieved value of type [" + value.getClass().getName() + "] for key [" +
key + "] " + "bound to thread [" + Thread.currentThread().getName() + "]";
log.trace(msg);
}
return value;
}
/**
* Binds value for the given key to the current thread.
*
*
A nullvalue has the same effect as if remove was called for the given
* key, i.e.:
*
*
* if ( value == null ) {
* remove( key );
* }
*
* @param key The key with which to identify the value.
* @param value The value to bind to the thread.
* @throws IllegalArgumentException if the key argument is null.
*/
public static void put(Object key, Object value) {
if (key == null) {
throw new IllegalArgumentException("key cannot be null");
}
if (value == null) {
remove(key);
return;
}
ensureResourcesInitialized();
resources.get().put(key, value);
if (log.isTraceEnabled()) {
String msg = "Bound value of type [" + value.getClass().getName() + "] for key [" +
key + "] to thread " + "[" + Thread.currentThread().getName() + "]";
log.trace(msg);
}
}
/**
* Unbinds the value for the given key from the current
* thread.
*
* @param key The key identifying the value bound to the current thread.
* @return the object unbound or null if there was nothing bound
* under the specified key name.
*/
public static Object remove(Object key) {
Map perThreadResources = resources.get();
Object value = perThreadResources != null ? perThreadResources.remove(key) : null;
if ((value != null) && log.isTraceEnabled()) {
String msg = "Removed value of type [" + value.getClass().getName() + "] for key [" +
key + "]" + "from thread [" + Thread.currentThread().getName() + "]";
log.trace(msg);
}
return value;
}
remove方法用于解绑key也就是删除key。注意这里remove方法会返回被删除的键值对。
操作SecurityManager及Subject的方法
/**
* Convenience method that simplifies retrieval of the application's SecurityManager instance from the current
* thread. If there is no SecurityManager bound to the thread (probably because framework code did not bind it
* to the thread), this method returns null.
*
* It is merely a convenient wrapper for the following:
*
* return (SecurityManager)get( SECURITY_MANAGER_KEY );
*
* This method only returns the bound value if it exists - it does not remove it
* from the thread. To remove it, one must call {@link #unbindSecurityManager() unbindSecurityManager()} instead.
*
* @return the Subject object bound to the thread, or null if there isn't one bound.
* @since 0.9
*/
public static SecurityManager getSecurityManager() {
return (SecurityManager) get(SECURITY_MANAGER_KEY);
}
/**
* Convenience method that simplifies binding the application's SecurityManager instance to the ThreadContext.
*
*
The method's existence is to help reduce casting in code and to simplify remembering of
* ThreadContext key names. The implementation is simple in that, if the SecurityManager is not null,
* it binds it to the thread, i.e.:
*
*
* @param securityManager the application's SecurityManager instance to bind to the thread. If the argument is
* null, nothing will be done.
* @since 0.9
*/
public static void bind(SecurityManager securityManager) {
if (securityManager != null) {
put(SECURITY_MANAGER_KEY, securityManager);
}
}
/**
* Convenience method that simplifies removal of the application's SecurityManager instance from the thread.
*
* The implementation just helps reduce casting and remembering of the ThreadContext key name, i.e it is
* merely a convenient wrapper for the following:
*
* return (SecurityManager)remove( SECURITY_MANAGER_KEY );
*
* If you wish to just retrieve the object from the thread without removing it (so it can be retrieved later
* during thread execution), use the {@link #getSecurityManager() getSecurityManager()} method instead.
*
* @return the application's SecurityManager instance previously bound to the thread, or null if there
* was none bound.
* @since 0.9
*/
public static SecurityManager unbindSecurityManager() {
return (SecurityManager) remove(SECURITY_MANAGER_KEY);
}
/**
* Convenience method that simplifies retrieval of a thread-bound Subject. If there is no
* Subject bound to the thread, this method returns null. It is merely a convenient wrapper
* for the following:
*
* return (Subject)get( SUBJECT_KEY );
*
* This method only returns the bound value if it exists - it does not remove it
* from the thread. To remove it, one must call {@link #unbindSubject() unbindSubject()} instead.
*
* @return the Subject object bound to the thread, or null if there isn't one bound.
* @since 0.2
*/
public static Subject getSubject() {
return (Subject) get(SUBJECT_KEY);
}
/**
* Convenience method that simplifies binding a Subject to the ThreadContext.
*
*
The method's existence is to help reduce casting in your own code and to simplify remembering of
* ThreadContext key names. The implementation is simple in that, if the Subject is not null,
* it binds it to the thread, i.e.:
*
*
* @param subject the Subject object to bind to the thread. If the argument is null, nothing will be done.
* @since 0.2
*/
public static void bind(Subject subject) {
if (subject != null) {
put(SUBJECT_KEY, subject);
}
}
/**
* Convenience method that simplifies removal of a thread-local Subject from the thread.
*
* The implementation just helps reduce casting and remembering of the ThreadContext key name, i.e it is
* merely a convenient wrapper for the following:
*
* return (Subject)remove( SUBJECT_KEY );
*
* If you wish to just retrieve the object from the thread without removing it (so it can be retrieved later during
* thread execution), you should use the {@link #getSubject() getSubject()} method for that purpose.
*
* @return the Subject object previously bound to the thread, or null if there was none bound.
* @since 0.2
*/
public static Subject unbindSubject() {
return (Subject) remove(SUBJECT_KEY);
}
昨晚和朋友聊天,喝了点咖啡,由于我经常喝茶,很长时间没喝咖啡了,所以失眠了,于是起床读JVM规范,读完后在朋友圈发了一条信息:
JVM Run-Time Data Areas:The Java Virtual Machine defines various run-time data areas that are used during execution of a program. So
Spark SQL supports most commonly used features of HiveQL. However, different HiveQL statements are executed in different manners:
1. DDL statements (e.g. CREATE TABLE, DROP TABLE, etc.)
nginx在运行过程中是否稳定,是否有异常退出过?这里总结几项平时会用到的小技巧。
1. 在error.log中查看是否有signal项,如果有,看看signal是多少。
比如,这是一个异常退出的情况:
$grep signal error.log
2012/12/24 16:39:56 [alert] 13661#0: worker process 13666 exited on s
方法一:常用方法 关闭XML验证
工具栏:windows => preferences => xml => xml files => validation => Indicate when no grammar is specified:选择Ignore即可。
方法二:(个人推荐)
添加 内容如下
<?xml version=
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml&quo
最主要的是使用到了一个jquery的插件jquery.media.js,使用这个插件就很容易实现了。
核心代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.