2013年7月31日星期三

Oracle's DDL, DML, DCL

 
DDL (Data Definition Language 数据定义语言
 
create table 创建表     
alter table 修改表
drop table 删除表
truncate table 删除表中所有行
create index 创建索引
drop index 删除索引
当执行DDL语句时,在每一条语句前后,oracle都将提交当前的事务。如果用户使用insert命令将记录插入到数据库后,执行了一条DDL语句(如create table),此时来自insert命令的数据将被提交到数据库。当DDL语句执行完成时,DDL语句会被自动提交,不能回滚。
 

DML (Data Manipulation Language 数据操作语言
insert 将记录插入到数据库
update 修改数据库的记录
delete 删除数据库的记录
当执行DML命令如果没有提交,将不会被其他会话看到。除非在DML命令之后执行了DDL命令或DCL命令,或用户退出会话,或终止实例,此时系统会自动发出commit命令,使未提交的DML命令提交。

DCL(Data Control Language 数据控制语句)的操作是数据库对象的权限,这些操作的确定使数据更加的安全。
 
   1.Grant statement : Allows the object's creator to a user or a group or all users (PUBLIC) certain rights.  
 
  2.Revoke statement : You can repeal a user or a group , or all user access.  
 
    
 
  Finally, there is something called "Data Query Language , abbreviated forget " refers to the select statement .  

Seeking solutions springMVC appears getOutputStream () has alreadybeen called for this response issue.


@RequestMapping(value="queryMenusForManage")
public @ResponseBody Map<String, Object> queryMenusForManage(ModelAndView mav, HttpServletRequest request, HttpServletResponse response) throws Exception {
List<SysMenu> menuList = menuService.queryMenusForManage();
dealMenu(menuList);
NodeTree<SysMenu> nodeTree = new NodeTree<SysMenu>();
List<SysMenu> dataList = nodeTree.getRootNodeTreeForJqgrid(menuList);
Map<String, Object> resultMap = new HashMap<String, Object>();
resultMap.put("rows", dataList);
return resultMap;
}


I return @ ResponseBody in the controller to the front, on display through freemarker, they reported errors such as the following, although the front page lacks impact, but the background has been so annoying error. Seeking solutions

java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:611)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:198)
at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:112)
at org.springframework.web.servlet.view.freemarker.FreeMarkerView.processTemplate(FreeMarkerView.java:366)
at org.springframework.web.servlet.view.freemarker.FreeMarkerView.doRender(FreeMarkerView.java:283)
at org.springframework.web.servlet.view.freemarker.FreeMarkerView.renderMergedTemplateModel(FreeMarkerView.java:233)
at org.springframework.web.servlet.view.AbstractTemplateView.renderMergedOutputModel(AbstractTemplateView.java:167)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1180)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:167)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:600)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1703)
at java.lang.Thread.run(Thread.java:662)

I am looking for the next,

org.springframework.web.servlet.view.freemarker.FreeMarkerView.processTemplate(FreeMarkerView.java:366)

This line of code is just calling getWriter (), so that the previous conflict.

template.process(model, response.getWriter());

------ Solution ------------------------------------- -------
I have encountered a problem, download video, file not found exception report. . But that address is accessible, the above is also the existence of the file. . .
------ Solution ---------------------------------------- ----
jsp try adding the following two lines
out.clear ();
out = pageContext.pushBody ();

------ Solution ------------------------------------ --------
seems to flow used twice, or not close
------ Solution ---------------- ----------------------------
series Use getOutputStream will report this error (getWriter underlying seemingly also use getOutputStream)

here that the series may be referring to the one obtained OutputStream not closed even the use.

but only from the landlord to the method given seemingly do not see signs of possible internal methods.
------ For reference only -------------------------------------- -
show is freemarker to achieve, no more no JAVA code JSP pages. Through the controller to return JSON to the foreground. iteye answer also fly more, saying it was unable to return map, void, mav, but I changed another return type nor
------ For reference only --------- ------------------------------
seemingly freemarker when rendering the foreground component called getWriter
- ---- For reference only ---------------------------------------
find Before looking for a place to get getOutputStream is not necessary to call, or early closure, similar to the second floor of the concepts presented.
------ For reference only -------------------------------------- -

and data types have to do with it? These data types are changed to call getWriter not a?
------ For reference only -------------------------------------- -
not fetch the wrong time, but in the display page when it was being given.
open a URL in order is the first display page, and then use AJAX to fetch data in the background. I take note off data JS method, it was found or an error, and eventually found with the use of EASYUI seemingly relevant. In the class = "easyui-linkbutton" removed after no error, and depressed ing ~ ~ ~ ~
Is it only me in this place, what a fault, check the Internet or downloaded are all verification code before being given to the

<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="showInfo()">编辑菜单</a>

------ For reference only ----------------------------------- ----
I also met with easyui datagrid display data on the wrong page to the last page, the page can not brush.
was resolved not?

HDU 4620 Fruit Ninja Extreme Search dfs

 

is dfs branch will be able to add a few less than one start dfs stack which causes the program to open the vector into an array like a giant slow search for time cards or caution STL tight right

 
  
#include <string> 
#include
<cstring>
#include
<algorithm>
#include
<cstdio>
#include
<iostream>
#include
<cmath>
#include
<queue>
#include
<vector>
#include
<set>
#include
<stack>
#include
<map>
#define maxn 320
#define maxe 10000*8
#define inf 1000000000
#define eps 1e-9
using namespace std;

struct node
{
int ti,id;
int num;
int tar[12];
void input()
{
int i;
scanf(
"%d %d",&num,&ti);
for(i=0; i<num; i++)
{
scanf(
"%d",&tar[i]);
}
}
bool operator<(const node& rhs)const
{
return ti<rhs.ti;
}
} p[
50];
int N,M,W;
bool vis[maxn];
int temp[40],ans[40];
int sum;
int ts,as;

void dfs(int cur,int pti)
{
int i,j;
if(ts>as)
{
copy(temp,temp
+ts,ans);
as=ts;
}
if(cur>=N)
{
return;
}
if(ts+N-cur<=as)
{
return;
}
if(M-sum<3)
{
return ;
}

for(i=cur; i<N; i++)
{
if((p[i].ti-pti>W)&&(pti!=-1))
{
break;
}

if(p[i].num<3) continue;
int tt[20];
int cnt = 0;
for(j=0;j<p[i].num;j++)
{
if(!vis[p[i].tar[j]])
{
tt[cnt
++] = p[i].tar[j];
}
}
if( cnt < 3 ) continue;

for(j=0;j<cnt;j++)
{
vis[tt[j]]
=1;
}
temp[ts
++]=p[i].id;
sum
+=cnt;

dfs(i
+1,p[i].ti);

sum
-=cnt;
ts
--;
for(j=0;j<cnt;j++)
{
vis[tt[j]]
=0;
}
}
}

int main()
{
//freopen("input.txt","r",stdin);
int i;
int T;
scanf(
"%d",&T);
while(T--)
{
scanf(
"%d %d %d",&N,&M,&W);
for(i=0; i<N; i++)
{
p[i].id
=i;
p[i].input();
}
sort(p,p
+N);
memset(vis,
0,sizeof(vis));
ts
=as=0;
sum
=0;
dfs(
0,-1);
sort(ans,ans
+as);
printf(
"%d\n",as);
for(i=0; i<as; i++)
{
printf(
"%d",ans[i]+1);
if(i==as-1)
{
puts(
"");
}
else
{
printf(
" ");
}
}
}
return 0;
}
 
 

Fine-grained parallel locks high KeyLock

 This post last edited by the icebamboo_moyun on 2013-07-20 18:26:34
a fine-grained locking, in some scenes than the synchronized, ReentrantLock such as a higher degree of parallelism for better performance, interested can look at
explain in particular: http://blog.csdn.net/icebamboo_moyun/article/details/9391915

KeyLock code:
public class KeyLock<K> {
// 保存所有锁定的KEY及其信号量
private final ConcurrentMap<K, Semaphore> map = new ConcurrentHashMap<K, Semaphore>();
// 保存每个线程锁定的KEY及其锁定计数
private final ThreadLocal<Map<K, LockInfo>> local = new ThreadLocal<Map<K, LockInfo>>() {
@Override
protected Map<K, LockInfo> initialValue() {
return new HashMap<K, LockInfo>();
}
};

/**
* 锁定key,其他等待此key的线程将进入等待,直到调用{@link #unlock(K)}
* 使用hashcode和equals来判断key是否相同,因此key必须实现{@link #hashCode()}和
* {@link #equals(Object)}方法
*
* @param key
*/
public void lock(K key) {
if (key == null)
return;
LockInfo info = local.get().get(key);
if (info == null) {
Semaphore current = new Semaphore(1);
current.acquireUninterruptibly();
Semaphore previous = map.put(key, current);
if (previous != null)
previous.acquireUninterruptibly();
local.get().put(key, new LockInfo(current));
} else {
info.lockCount++;
}
}

/**
* 释放key,唤醒其他等待此key的线程
* @param key
*/
public void unlock(K key) {
if (key == null)
return;
LockInfo info = local.get().get(key);
if (info != null && --info.lockCount == 0) {
info.current.release();
map.remove(key, info.current);
local.get().remove(key);
}
}

/**
* 锁定多个key
* 建议在调用此方法前先对keys进行排序,使用相同的锁定顺序,防止死锁发生
* @param keys
*/
public void lock(K[] keys) {
if (keys == null)
return;
for (K key : keys) {
lock(key);
}
}

/**
* 释放多个key
* @param keys
*/
public void unlock(K[] keys) {
if (keys == null)
return;
for (K key : keys) {
unlock(key);
}
}

private static class LockInfo {
private final Semaphore current;
private int lockCount;

private LockInfo(Semaphore current) {
this.current = current;
this.lockCount = 1;
}
}
}

------ Solution ------------------------------------- -------
read your blog do on tests, I have a faster way.

is no transfer function, as follows:
public class Test {

  private final AtomicInteger[] iAccounts;
  public Test(int count, int money) {
    iAccounts = new AtomicInteger[count];
    for (int i = 0; i < count; i++)
      iAccounts[i] = new AtomicInteger(money);
  }

  void transferAtomic(int from, int to, int money) {
    if (iAccounts[from].get() < money)
      return;
    iAccounts[from].getAndAdd(-money);
    try {
      Thread.sleep(2);
    }
    catch (Exception e) {
    }
    iAccounts[to].getAndAdd(money);
  }
//...以下略


Create a TransferRunner, with transferAtomic instead transfer function.

This method is faster than using KeyLock 10 times. Test when removing the phrase sleep, get the code of pure efficiency

difference is:
1. KeyLock each account for two of the lock, and transferAtomic is essentially a time lock an account, that is, it will turn out and transferred as two separate operations: this does not affect the correctness of carrying
2. KeyLock many memory allocation (boxing operation, Semaphore, including lock before Integer {key1, key2}), Hash query, rather than no transferAtomic addition to initializing memory allocation and Hash inquiry and therefore more efficient

In fact, when you need to use KeyLock always better alternative (at least I think have to use KeyLock scene), because it is the nature of the two objects were locked (not at the same time, except in the lock () function rejoined synchronization mechanisms).

------ Solution ------------------------------------ --------
have never used semaphores, modeled on the code you write a class with ordinary Object locked, with a ConcurrentHashMap and double-checked lock to guarantee obtain repeatable read lock lock free:



import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class KeyLocks<L> {
 
  private final Map<L, Object> locks = new ConcurrentHashMap<L, Object>();
 
  public Object getLock(L key) {
   
    Object result = locks.get(key);
    if( result == null ) synchronized (locks) {
     
      result = locks.get(key);
      if( result == null ) {
       
        result = new Object();
        locks.put(key, result);
      }
    }
    return result;
  }
}

class Test {
 
  private final int[] accounts;
  private final KeyLocks<Integer> keyLocks;
 
  Test(int count, int money) {
   
    if( count <= 0 )
      throw new IllegalArgumentException("Invalid number of accounts: " + count);
    if( money < 0 )
      throw new IllegalArgumentException("Invalid initial balance: " + money);
   
    accounts = new int[count];
    for(int i=0; i<accounts.length; i++)
      accounts[i] = money;
   
    keyLocks = new KeyLocks<Integer>();
  }
 
  boolean transfer(int from, int to, int money) {
   
    if( from < 0 || from >= accounts.length )
      throw new IndexOutOfBoundsException("Invalid from account: " + from);
   
    if( to < 0 || to >= accounts.length )
      throw new IndexOutOfBoundsException("Invalid to account: " + to);
   
    if( from == to )
      throw new IllegalArgumentException("Cannot transfer between same account.");
   
    if( money < 0 )
      throw new IllegalArgumentException("Invalid transfer amount: " + money);
   
    synchronized (keyLocks.getLock(from)) {
       
        if( accounts[from] < money )
          return false;
       
        accounts[from] -= money;
    }
    synchronized (keyLocks.getLock(to)) {
     
      accounts[to] += money;
    }
    return true;
  }
}


I do not know each visit ThreadLocal and establish how much overhead Semaphore instance, perhaps negligible, then the efficiency of these two implementations may be similar.
------ For reference only -------------------------------------- -
top!
JDK few?
------ For reference only -------------------------------------- -

1.5 +
------ For reference only ---------------------------- -----------
Oh, this is the realization of their own, not the JAVA comes
------ For reference only ----------- ----------------------------
landlord strong ah my generation catching objects
----- - For reference only ---------------------------------------

------ For reference only --- ------------------------------------

------ For reference only ---------- -----------------------------
forgot to say, if you bring sleep, closer to the actual application scenario, transferAtomic still KeyLock faster than about 20%, mainly due to speak in front of the first point, transferAtomic locked while only one account
------ For reference only -------------- -------------------------

Well, yes, this is indeed something worse performance. This is what I used to do caching tool, which looks like the scene

//用户信息
class UserInfo {
String name;
String phone;
}

interface UserInfoDao {
// 获取用户信息
UserInfo getUserInfo(int userId);

// 更新用户信息
void updateUserInfo(int userId, UserInfo userInfo);
}

class UserInfoDaoImpl implements UserInfoDao {

@Override
public UserInfo getUserInfo(int userId) {
UserInfo info = null;
// 数据库取数据
return info;
}

@Override
public void updateUserInfo(int userId, UserInfo userInfo) {
// 更新数据库
}

}

//带缓存的DAO
class UserInfoDaoCachedImpl implements UserInfoDao {
ConcurrentMap<Integer, UserInfo> cache;
UserInfoDaoImpl innerDao;
KeyLock lock;

@Override
public UserInfo getUserInfo(int userId) {
UserInfo info = cache.get(userId); // 先从缓存取
if (info == null) {
lock.lock(userId);// 缓存无数据则锁定ID
try {
info = innerDao.getUserInfo(userId);// 数据库取
if (info != null) {
cache.put(userId, info); // 更新缓存
}
} finally {
lock.unlock(userId);
}
}
return info;
}

@Override
public void updateUserInfo(int userId, UserInfo userInfo) {
lock.lock(userId);
try {
innerDao.updateUserInfo(userId, userInfo);
cache.put(userId, userInfo);
} finally {
lock.unlock(userId);
}
}
}



------ For reference only ---------------------------------- -----
In fact, I did not understand the role of lock here. Any time you want to ensure the consistency of the cache and the Dao?
The only problem when something like this:
T1 updateUserInfo, T2 getUserInfo, this time T1 DB was not updated when updating the cache, T2 acquired the cache, and DB inconsistent.
However, to solve this problem, as long as the cache is updated when the first updateUserInfo not enough?

may be your code did not paste the full, so do not find the reason for non-
------ For reference only --------------- ------------------------


is to ensure that the data in the cache and database consistency
But the problem is not you said that.
imagine it not a locking scenario:
T1 and T2 simultaneously update id to 0 users' information, T1 to update infoA, T2 to be updated as infoB
T1 first complete innerDao.updateUserInfo (0, infoA);
T2 completed innerDao.updateUserInfo (0, infoB);
At this time the database is stored infoB
then
T2 first complete cache.put (0, infoB);
T1 completed cache.put (0, infoA);
when the cache memory is infoA, cache memory and database stored data is not the same

If the entire updateUserInfo locking, we can guarantee the cache, the database is consistent, there can be only a single thread at a time in the update, the other had to wait, even if they are not updated with a user

but with KeyLock right ID locking, both to ensure data consistency but also improve the degree of parallelism: threads operating on the same ID mutex ID for different threads operating in parallel.
although the locking overhead is large, but when compared with the basic database operations is negligible
------ For reference only --------------- ------------------------


carefully read your example, you are not locked in the case of the first judgment and then transfer the account balance is unsafe
For example there are 500 yuan accounts 0, T1 and T2 be transferred out from the account 0 300 yuan
T1 and T2 simultaneously into the balance of judgment, two threads are met 500> 300, have entered into deducting money transfer processing, when two threads have finished processing their account balance is 0 -100 yuan
------ For reference only --------------------------------------- < br>
  
carefully read your example, you are not locked in the case of the first judgment and then transfer the account balance is unsafe   
For example there are 500 yuan accounts 0, T1 and T2 be transferred out from the account 0 300 yuan   
T1 and T2 simultaneously into the balance of judgment, two threads are met 500> 300, have entered into deducting money transfer processing, when two threads have finished processing their account balance is 0 -100 million  

my test code also ignore this, the lock should be added before the judge
------ For reference only ------------------- --------------------
thing. . This is really wrong. But with a lock array seemingly on the line it
------ For reference only ---------------------------- -----------
indeed reasonable scenarios
------ For reference only ------------------ ---------------------

array lock that you put all the threads are mutually exclusive, and locks almost the entire way.
lock array + sleep () must not be KeyLock high efficiency
------ For reference only ---------------------------------------
I'm not locked array. Or look at the code and intuitive, I think the performance KeyLock is this:
public class KeyLock<T> {
  private Map<T, Lock> iLocksMap;

  private Lock iAllocationLock = new ReentrantLock();

  public KeyLock() {
    iLocksMap = new ConcurrentHashMap<>();
  }

  public void lock(T key) {
    Lock existingLock = iLocksMap.get(key);
    if (existingLock != null) {
      existingLock.lock();
      return;
    }

    try {
      iAllocationLock.lock();
      Lock newLock = iLocksMap.get(key);
      if (newLock == null) {
        newLock = new ReentrantLock();
        iLocksMap.put(key, newLock);
      }
      newLock.lock();
      return;
    }
    finally {
      iAllocationLock.unlock();
    }
  }

  public void unlock(T key) {
    Lock existingLock = iLocksMap.get(key);
    if (existingLock != null) {
      existingLock.unlock();
      return;
    }

    try {
      iAllocationLock.lock();
      existingLock = iLocksMap.get(key);
      if (existingLock != null)
        existingLock.unlock();
    }
    finally {
      iAllocationLock.unlock();
    }
  }
}

------ For reference only ----------------------------------- ----

ah, yes, your implementation to meet the needs of (unlock method where it should be cleaned map try it?)

I'm taking into account that the lock reentrancy and fairness so the code will be complicated point

------ For reference only ---------------------------------- -----
here try to prevent someone from simultaneous access iLocksMap.get (key), and then have got null. Then this two thread must have only one able to create Lock, otherwise there will be more in the same Key Lock on.

not directly try to performance considerations, not every lock or unlock should call iAllocationLock. In fact, this implementation is also very fair, you can also re-entry

------ For reference only ---------------------------------- -----


ah, carefully read your code and found a few minor problems, you may consider not very thorough, honest multithreaded something really nerve-wracking. . . :
1, iLocksMap not been cleaned since key range is not limited, so the map will limit growth
2, the lock is not fair, equitable lock request is the first get a lock first, new ReentrantLock (true) is a fair locks, new ReentrantLock () non-fair. When you use this internal lock control, it must also be non-fair
3, in some cases, a different key is also mutually exclusive, that is, one thread to another thread can lock lock key1 key2. This situation is a bit complicated, combine your KeyLock lines of code to illustrate:

T1 requests lock keyA, execution to line 22, will newLock into the iLocksMap, but not yet performed on line 23
same time T2 lock request keyA, execution to line 13, get existingLock lock, then return
T1 waiting in a line 24
T3 request lock keyB, waiting in a line 18, as iAllocationLock obtained by T1, T1 waiting in line 24
this case the request keyB T3 T1, T2 and the request is not in parallel keyA, T3 T1 must wait for the release of, T2 obtained, T2 release line 18 to get iAllocationLock

------ For reference only ---------------------------------- -----
ah, but also discovered a cause deadlock situation, the more serious, and in the same thread KEY lock request two cases, the same combination of lines of code Description:
T1 requests lock keyA, execution to line 22, will newLock into the iLocksMap, but not yet performed on line 23
same time T2 lock request keyA, execution to line 13, get existingLock lock, then return
T1 waiting in a line 24
T2 requested again locked keyB, waiting in a line 18, as iAllocationLock obtained by T1, T1 waiting in line 24
this case
T1 get iAllocationLock waiting newLock
T2 get existingLock waiting iAllocationLock
As newLock and existingLock is the same lock, so the deadlock
------ For reference only --------------------- ------------------


This code is clearly a problem:


    // ...
    if (iAccounts[from].get() < money)
      return;
    iAccounts[from].getAndAdd(-money);
    // ...


------ For reference only ---------------------------------- -----
it really is a problem. .
If we try inside newlock.lock finally put on the line after a seemingly
------ For reference only ------------------- --------------------


agree with what you said, if specific to a particular scene should always have a more optimal way to achieve this.

AtomicInteger problem is that it does not support the "read, check and then decide whether to write" This complex combination of atomic protection.
------ For reference only -------------------------------------- -


measured over overhead, KeyLock ReentrantLock locking overhead is about 3 times, so it is more suitable for processing time-consuming scenarios

your implementation does not take into account the locks map release because key range is uncertain during operation can handle thousands of different key, you can think about the java virtual reference, there may be methods to solve your code locks release
------ For reference only ------------------------------ ---------
do map clean, in addition to track outside threadlocal seemingly no good way. Even adding a dumpLock () function, improper use is still very prone IllegalMonitorStateException. Like this
public class KeyLock<T> {
  private final Map<T, Lock> iLocksMap;

  private final boolean iFair;

  private Lock iAllocationLock;

  public KeyLock(boolean fair) {
    iFair = fair;
    iLocksMap = new ConcurrentHashMap<>();
    iAllocationLock = new ReentrantLock(iFair);
  }

  public void lock(T key) {
    Lock existingLock = iLocksMap.get(key);
    if (existingLock != null) {
      existingLock.lock();
      return;
    }

    Lock newLock = null;
    try {
      iAllocationLock.lock();
      newLock = iLocksMap.get(key);
      if (newLock == null) {
        newLock = new ReentrantLock(iFair);
        iLocksMap.put(key, newLock);
      }
      return;
    }
    finally {
      iAllocationLock.unlock();
      newLock.lock();
    }
  }

  public void unlock(T key) {
    Lock existingLock = iLocksMap.get(key);
    if (existingLock != null) {
      existingLock.unlock();
      return;
    }

    try {
      iAllocationLock.lock();
      existingLock = iLocksMap.get(key);
      if (existingLock != null)
        existingLock.unlock();
    }
    finally {
      iAllocationLock.unlock();
    }
  }

  public void dumpLock(T key) {
    if (iLocksMap.remove(key) != null)
      return;

    try {
      iAllocationLock.lock();
      if (iLocksMap.remove(key) != null)
        return;
    }
    finally {
      iAllocationLock.unlock();
    }

    iLocksMap.remove(key);
  }

------ For reference only ----------------------------------- ----
landlord link this example is also problematic:


    private int[] accounts; 
    private KeyLock<Integer> lock = new KeyLock<Integer>(); 
     
    public boolean transfer(int from, int to, int money) { 
        Integer[] keys = new Integer[] {from, to}; 
        Arrays.sort(keys); //对多个key进行排序,保证锁定顺序防止死锁 
        lock.lock(keys); 
        try { 
            //处理不同的from和to的线程都可进入此同步块 
            if (accounts[from] < money) 
                return false; 
            accounts[from] -= money; 
            accounts[to] += money; 
            return true; 
        } finally { 
            lock.unlock(keys); 
        } 
    } 


(Incidentally, it should be inside the KeyLock KeyLock bar)

Assuming account 3 500
If there are two operations occur simultaneously on two thread:

transfer 300 from 3-5
transfer 300 from 3-6

Since {3,5} and {3,6} are not equal two locks, will lead to two threads may simultaneously access to the account three, like 3 is not locked to protect the same.
------ For reference only -------------------------------------- -
unlock the iAllocationLock step can also be released earlier

public void unlock(T key) {
    Lock existingLock = iLocksMap.get(key);
    if (existingLock != null) {
      existingLock.unlock();
      return;
    }

    try {
      iAllocationLock.lock();
      existingLock = iLocksMap.get(key);
    }
    finally {
      iAllocationLock.unlock();
      if (existingLock != null)
        existingLock.unlock();
    }
  }

------ For reference only ----------------------------------- ----


This code is called in this way

    /**
     * 锁定多个key
     * 建议在调用此方法前先对keys进行排序,使用相同的锁定顺序,防止死锁发生
     * @param keys
     */ 
    public void lock(K[] keys) { 
        if (keys == null) 
            return; 
        for (K key : keys) { 
            lock(key); 
        } 
    }

were requested two key locks instead of Integer [] as requested lock
------ For reference only ---------------- -----------------------

Here he lock (K [] keys) is locked the keys were in the key, not the whole keys as a lock to treat
------ For reference only --------------------------- ------------

Well, if you do not consider iLocksMap cleanup problem is easier to solve, plus clean-up code also becomes complicated
------ For reference only ---------------------------------------

  
measured over overhead, KeyLock ReentrantLock locking overhead is about 3 times, so it is more suitable for processing time-consuming scenarios   
  
your implementation does not take into account the locks map release because key range is uncertain during operation can handle thousands of different key, you can think about the java virtual reference, there may be solution to the release of your code locks  


mechanisms are not familiar with the GC, if a thread using a Object to monitor, count as strong references? If you count it, maybe you can use a similar WeakHashMap means.
------ For reference only -------------------------------------- -

Here he lock (K [] keys) is locked the keys were in the key, not the entire keys treated as a lock  


uh, I was wrong, sorry, with the sort to solve the deadlock problem, thinking too clever, learned
------ For reference only -------- -------------------------------

  
This code is called in this way   
  

    /**
     * 锁定多个key
     * 建议在调用此方法前先对keys进行排序,使用相同的锁定顺序,防止死锁发生
     * @param keys
     */ 
    public void lock(K[] keys) { 
        if (keys == null) 
            return; 
        for (K key : keys) { 
            lock(key); 
        } 
    }
  
were requested two key locks instead of Integer [] as requested lock  


upstairs
------ For reference only -------------------------------- -------

    
measured over overhead, KeyLock ReentrantLock locking overhead is about 3 times, so it is more suitable for processing time-consuming scenarios     
    
your implementation does not take into account the locks map release because key range is uncertain during operation can handle thousands of different key, you can think about the java virtual reference, there may be solution to the release of your code locks    
  
  
  
mechanisms are not familiar with the GC, if a thread using a Object to monitor, count as strong references? If you count it, maybe you can use a similar WeakHashMap means.  


This I was not very clear, if you can use it to achieve asynchronous cleanup, then, coupled with internal lock object is used, then its performance would surely be much better realization of the program of my
------ For reference only ---------------------------------------

he Here lock (K [] keys) are separately locked keys in the key, not the entire keys treated as a lock    
  
  
  
uh, I was wrong, sorry, with the sort to solve the deadlock problem, thinking too clever, learning  


sort to solve the deadlock problem I had reservations, this approach is too easy an inexplicable error (assuming the user did not carefully read the document), and the efficiency is not high, and sometimes even impossible (if I can not sort the Key ?)
------ For reference only ------------------------------------ ---

      
measured over overhead, KeyLock ReentrantLock locking overhead is about 3 times, so it is more suitable for processing time-consuming scenarios       
      
your implementation does not take into account the locks map release because key range is uncertain during operation can handle thousands of different key, you can think about the java virtual reference, there may be solution to the release of your code locks      
    
    
    
mechanisms are not familiar with the GC, if a thread using a Object to monitor, count as strong references? If you count it, maybe you can use a similar WeakHashMap means.    
  
  
  
This I was not very clear, if you can use it to achieve asynchronous cleanup, then, coupled with internal lock object is used, then its performance would surely be a lot better of my implementations  

ReentrantLock
I looked at the source, did not find it passes a reference to the underlying themselves. Underlying reference is NonfairSync or FairSync, although they are ReentrantLock inner class, but they are static, so it does not depend on ReentrantLock instance. I guess even the thread to hold live lock, then the lock itself or can be garbage collected (assuming no any strong references). Try this test to see.

------ For reference only ---------------------------------- -----

Here he lock (K [] keys) is locked the keys were in the key, not the entire keys treated as a lock      
    
    
    
uh, I was wrong, sorry, with the sort to solve the deadlock problem, thinking too clever, learning    
  
  
  
sort to solve the deadlock problem I had reservations, this approach is too easy an inexplicable error (assuming the user did not carefully read the document), and the efficiency is not high, and sometimes even impossible (if I can not sort the Key ?)  

'd certainly not efficient, sort it touches only pass a Comparator on the line, there is no need KEY natural order, as long as all of the same order of processing requests on the line. Fortunately, I do not need real applications simultaneously lock multiple KEY. . .
------ For reference only -------------------------------------- -
Supreme giving birth to ah ~
------ For reference only ----------------------------- ----------
here have to add conditions, Comparator return equal time. equals must return the same, otherwise it will go wrong. Overall a bit too limited sense
------ For reference only ------------------------------- --------



        
        
measured over overhead, KeyLock ReentrantLock locking overhead is about 3 times, so it is more suitable for processing time-consuming scenarios         
        
your implementation does not take into account the locks map release because key range is uncertain during operation can handle thousands of different key, you can think about the java virtual reference, there may be solution to the release of your code locks        
      
      
      
mechanisms are not familiar with the GC, if a thread using a Object to monitor, count as strong references? If you count it, maybe you can use a similar WeakHashMap means.      
    
    
    
This I was not very clear, if you can use it to achieve asynchronous cleanup, then, coupled with internal lock object is used, then its performance would surely be a lot better of my implementations    
  
  
  ReentrantLock
I looked at the source, did not find it passes a reference to the underlying themselves. Underlying reference is NonfairSync or FairSync, although they are ReentrantLock inner class, but they are static, so it does not depend on ReentrantLock instance. I guess even the thread to hold live lock, then the lock itself or can be garbage collected (assuming no any strong references). Try this test to see.   
 


probably a little bit beyond the scope of my abilities, like a long time did not come up with a pilot program ......
just google a bit did not find ready-made answers, turned a bit JLS 7 and oracle of the JVM specification did not find the answer ......
------ For reference only ---------------------------------------
what way multithreading it has not been very high concurrent understand, do not know that there is nothing good article easy to understand!
------ For reference only -------------------------------------- -

          
measured over overhead, KeyLock ReentrantLock locking overhead is about 3 times, so it is more suitable for processing time-consuming scenarios           
          
your implementation does not take into account the locks map release because key range is uncertain during operation can handle thousands of different key, you can think about the java virtual reference, there may be solution to the release of your code locks          
        
        
        
mechanisms are not familiar with the GC, if a thread using a Object to monitor, count as strong references? If you count it, maybe you can use a similar WeakHashMap means.        
      
      
      
This I was not very clear, if you can use it to achieve asynchronous cleanup, then, coupled with internal lock object is used, then its performance would surely be a lot better of my implementations      
    
    
    ReentrantLock
I looked at the source, did not find it passes a reference to the underlying themselves. Underlying reference is NonfairSync or FairSync, although they are ReentrantLock inner class, but they are static, so it does not depend on ReentrantLock instance. I guess even the thread to hold live lock, then the lock itself or can be garbage collected (assuming no any strong references). Try this test to see.     
   
  
  
  
probably a little bit beyond the scope of my abilities, like a long time did not come up with a pilot program ......   
just google a bit did not find ready-made answers, turned a bit JLS 7 and oracle of the JVM specification did not find the answer ......  


Let me talk about experimental program, and then we do together.
build a MyReetrantLock class inherits ReentrantLock, and override the finalize method it outputs a prompt
use WeakReference to establish a lock, and then let a thread lock it.
This thread constantly creating new objects and placed in an ArrayList, forcing the JVM garbage recycling
sometimes call it System.gc ()
Finally release the lock, empty ArrayList, and then repeat the previous steps, sleep for a while.
last output
------ For reference only ------------------------------- --------
test code:
public class Father {

  public static void main(String args[]) {
    new Thread(new Runnable() {
      @Override
      public void run() {
        MyLock strongLock = new MyLock();
        WeakReference<MyLock> weakLock = new WeakReference<MyLock>(strongLock);
        strongLock.lock();
        System.out.println("locked");
        strongLock = null;

        System.out.println("Allocation like crazy");
        List<String> garbage = new ArrayList<String>();
        for (int i = 0; i < 1000000; i++) {
          garbage.add(String.valueOf(i));
        }

        System.out.println("calling gc");
        System.gc();

        try {
          Thread.sleep(1000);
        }
        catch (InterruptedException e) {
          //ignore
        }

        MyLock lock = weakLock.get();
        if (lock == null) {
          System.out.println("damn!");
          return;
        }
        else {
          lock.unlock();
        }

        garbage.clear();

        System.out.println("Allocation like crazy again");
        for (int i = 1000000; i < 2000000; i++) {
          garbage.add(String.valueOf(i));
        }

        System.out.println("calling gc");
        System.gc();
        try {
          Thread.sleep(1000);
        }
        catch (InterruptedException e) {
          // ignore
        }

        if (weakLock.get() == null)
          System.out.println("hooray!!");
      }
    }).start();
  }

  private static class MyLock extends ReentrantLock {
    @Override
    public void finalize() {
      System.out.println("Hi this is me, a lock! But I'm dying, see ya");
    }
  }
}


Test Results:
locked
Allocation like crazy
Hi this is me, a lock! But I'm dying, see ya
calling gc
damn!

prove Lock even if they are thread has also been recovered (it seems I was right before the estimates..)
------ For reference only ------------ ---------------------------

have a solution for any KEY hash value locked
------ For reference only ---------------------------------------
  The reply deleted by an administrator at 2013-07-25 12:27:34

------ For reference only ---------------------------------- -----

have a solution for any hash value locked KEY  


int hash = key.hashCode();
lock.lock(hash);
try {
//do something
} finally {
lock.unlock(hash);
}


------ For reference only ---------------------------------- -----

"Java concurrent programming combat" http://www.amazon.cn/Java% E5% B9% B6% E5% 8F% 91% E7% BC% 96% E7% A8% 8B% E5% AE% 9E% E6% 88% 98 -% E7% 9B% 96% E8% 8C% A8/dp/B0077K9XHW/ref = sr_1_1? s = books & ie = UTF8 & qid = 1374725184 & sr = 1-1 & ; keywords = java +% E5% B9% B6% E5% 8F% 91
This book is good.
------ For reference only -------------------------------------- -

have a solution for any hash value locked KEY    
  
  
  

int hash = key.hashCode();
lock.lock(hash);
try {
//do something
} finally {
lock.unlock(hash);
}
  
 


did not understand. . What solved the problem?
------ For reference only -------------------------------------- -

have a solution for any hash value locked KEY      
    
    
    

int hash = key.hashCode();
lock.lock(hash);
try {
//do something
} finally {
lock.unlock(hash);
}
    
   
  
  
  
did not understand. . What solved the problem?  

key only implement the hashCode method on the line, meaning that with int values ​​for key mapping, and then lock it int value
------ For reference only ----------- ----------------------------
but this does not infinite loop?
------ For reference only -------------------------------------- -

code are not circulating. . .
not the only way to use hash lock would happen is that they are two different key hash value, like two threads simultaneously on these two key when mutually exclusive, as is its recognition KeyLock hash value
with hash to lock also has the benefit of its internal KeyLock MAP efficient because judgment is equal to the Integer, its hashCode and equals methods, high efficiency
------ For reference only - --------------------------------------


In this case, it is not at liberty to release the map in the lock ......
------ For reference only -------------------- -------------------

code are not circulating. . .   
not the only way to use hash lock would happen is that they are two different key hash value, like two threads simultaneously on these two key when mutually exclusive, as is its recognition KeyLock hash value   
with hash to lock also has the benefit of its internal KeyLock MAP efficient because judgment is equal to the Integer, its high efficiency hashCode and equals methods  


o, you mean that the external code to call hashCode, I thought it was inside the KeyLock such processing. .
Whether internal or external certainly not do so, and the reason is that you say the piece hash value conflicts. In this context the efficiency of pointless discussion, because correctness is the first one. Of course, if you say that particular scenario, it is no problem, but even with a trove of TIntegerObjectMap should replace your ConcurrentMap, efficient.

------ For reference only ---------------------------------- -----
ah. . Achieve a daemon thread cleanup on map
public class KeyLock2<T> {
  private final Map<T, Lock> iLocksMap;

  private final boolean iFair;

  private Lock iAllocationLock;

  private Lock iFreeMapLock;

  private ScheduledExecutorService iExecutor;

  public KeyLock2(boolean fair, long collectionRateMilli) {
    iFair = fair;
    iLocksMap = new ConcurrentHashMap<T, Lock>();
    iAllocationLock = new ReentrantLock(iFair);

    iFreeMapLock = new ReentrantLock();
    iExecutor = Executors.newScheduledThreadPool(1);

    iExecutor.scheduleWithFixedDelay(new Runnable() {
      @Override
      public void run() {
        dumpLocks();
      }
    }, 0, collectionRateMilli, TimeUnit.MILLISECONDS);
  }

  public void lock(T key) {
    Lock newLock = null;
    try {
      iAllocationLock.lock();
      newLock = iLocksMap.get(key);
      if (newLock == null) {
        newLock = new ReentrantLock(iFair);
        iLocksMap.put(key, newLock);
      }
      return;
    }
    finally {
      iAllocationLock.unlock();
      if (newLock != null)
        newLock.lock();
    }
  }

  public void unlock(T key) {
    Lock existingLock;
    try {
      iAllocationLock.lock();
      existingLock = iLocksMap.get(key);
    }
    finally {
      iAllocationLock.unlock();
    }

    if (existingLock != null)
      existingLock.unlock();
  }

  public void dumpLocks() {
    iFreeMapLock.lock();
    try {
      for (Iterator<Map.Entry<T, Lock>> entryIter = iLocksMap.entrySet().iterator(); entryIter.hasNext();/*empty*/) {
        Map.Entry<T, Lock> entry = entryIter.next();
        if (entry.getValue().tryLock()) {
          iAllocationLock.lock();
          try {
            entryIter.remove();
          }
          finally {
            iAllocationLock.unlock();
          }
        }
      }
    }
    finally {
      iFreeMapLock.unlock();
    }
  }
}

------ For reference only ----------------------------------- ----

it might as well use my program it directly. . .
Each KeyLock object contains a cleanup thread that the procedures can be more than just a KeyLock object ID of personnel have locked with the lock on the work order ID, there are right. . .
------ For reference only -------------------------------------- -
but they can be used with a KeyLock object ah
------ For reference only ------------------------ ---------------

can not, for example, who has an ID of 1, work orders have an ID of 1, they interfere with each other, without mutual exclusion < br> ------ For reference only ---------------------------------------
class LockKey {
private int iKey;
private int iType;
private LockKey (int key, int type) {
iKey = key;
iType = type;
}

public static getIDLockKey (int key) {
return new LockKey (key, 0);
}

public static getBillLockKey (int key) {
return new LockKey (key, 1);
}

public int getKey () {
}

public boolean equals (Object o) {
if (! o instanceof LockKey)
return false;
return (LockKey) o.iKey == iKey
}
}
------ For reference only --------------------------------- ------
accidentally hit ctrl + enter. . .

class LockKey {
  private int iKey;
  private int iType;
  private LockKey (int key, int type) {
    iKey = key;
    iType = type;
  }

  public static getIDLockKey (int key) {
    return new LockKey(key, 0);
  }

  public static getBillLockKey (int key) {
    return new LockKey(key, 1);
  }

  public int getKey() {
    return iKey;
  }

  public boolean equals (Object o) {
    if (o == null || !o instanceof LockKey)
      return false;
    return ((LockKey) o).iKey == iKey && ((LockKey) o).iType == iType;
  }

  public int hashCode() {
    return iKey * 17 + (iKey << iType) * 17;
  }
}


so it can be shared KeyLock

Under Ubuntu apt

 

sudo apt-get update encounter Hash Sum Mismatch

 

Solution :

 

with goagent in the case of :

 

sudo apt-get-o Acquire :: http::proxy = "http://127.0.0.1:8087/" update

 

No goagent words. . Some other methods online , does not seem tricky, try it :

 

sudo rm-rf / var / lib / apt / lists / *

 

sudo apt-get clean

 

sudo apt-get update - fix-missing

java.lang.NoClassDefFoundError:org/apache/commons/lang3/StringUtils error exception

2013-4-28 13:17:57 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter struts2
java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:211)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:102)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:226)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:429)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:473)
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:295)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4072)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4726)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtils
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 35 more


this problem, depressed for a long time, with a variety of methods online Great God, are not resolved.

Then I deleted the struts2 project actually appeared the same run-time exception, really feel this exception is very egg pain

original when there is no error, that is, when the last few days to do hibernate,

seeking brightest Great God help me either Weapon abnormal, or direct me to completely remove

I appreciate it!



------ Solution ------------------------------------ --------
org/apache/commons/lang3/StringUtils

look at your commons-lang's jar, there is no StringUtils this class
------ Solution ------------------- -------------------------
/ lang3/StringUtil, you need to upgrade to a new version of commons-lang.jar
- ---- Solution -------------------------------------------- < br> Reply to: 2013-04-28 14:43:37
/ lang3/StringUtil, you need to upgrade to a new version of commons-lang.jar
------ Solution ------------------- -------------------------
Tomcat clean look.
------ Solution ---------------------------------------- ----
missing wrapped up,
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtils

Do you have a way to use this method!

clean look to try, as well as to the Task Manager to see if there two javaw running, were shut reopen try
------ For reference only ---- -----------------------------------
I deleted this project is still there this anomaly is how the matter? ?
------ For reference only -------------------------------------- -
Oo own solution, I made a mistake

So this is a problem with the filter also made me think that the project has an exception.

decisively changed the web.xml file under


and Google the next, I'm using struts2 higher version struts2.3.4, this version has its own xwork This package contains decisively put xwork-2.0.4.jar deleted

solved the problem immediately

what is my jar package


------ For reference only ---------------------------------- -----

------ For reference only ---------------------------------------
楼上的commons-fileupload-1.2.1.jar  应该改成 commons-fileupload-1.2.2.jar 
     freemarker-2.3.15.jar应改成 freemarker-2.3.19.jar




http://blog.csdn.net/jeffyu328/article/details/7721022

------ For reference only --------------------------------------- < br> I encountered the same problem, I imported commons-lang3-3.1.jar package, starts normally, buttoned! ! !
------ For reference only -------------------------------------- -


positive solution!
------ For reference only -------------------------------------- -
I use the 2.3 version of the lang pack. Do not want to use the 3.1 version of the.
But why is the 3.1 version of the package will go to it.
------ For reference only -------------------------------------- -
good, thank you Lou!
------ For reference only -------------------------------------- -
I press myswwy method is feasible
------ For reference only ------------------------- --------------
missing package, like
pasted in.

mysql5.5 under linux installation

 

# rpm-qa | grep-i mysql view installed mysql version

 

If you have an existing mysql version  delete

 

installation services and client, go to Oracle official website to download:

 

# rpm-ivh MySQL-server-5.5.28-1.linux2.6.i386.rpm

 

# rpm-ivh MySQL-client-5.5.28-1.linux2.6.i386.rpm

 

after installation, the following message will appear, prompting the design do not forget the root password, and other information.

 

then see whether the service mysql start  # netstat-nat

 

see 3306 as the port number, it shows service startup, the default port is 3306, if not start, then open the service # service mysql start start mysql service.

 

then enter the mysql, if the following message appears, indicating success.

 

Welcome to the MySQL monitor. Commands end with; or \ g. Your MySQL connection id is 1 Server version: 5.5.16 MySQL Community Server (GPL)

 

Copyright (c) 2000, 2011, Oracle and / or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and / or its affiliates. Other names may be trademarks of their respective owners.

 

Type 'help;' or '\ h' for help. Type '\ c' to clear the current input statement.

 

Go to mysql database: mysql> use mysql;

 

Then look at the root of the situation select user, password form user;

 

Change Password  update user set password = password ('newpassword') where user = 'root' and host = 'root' or host = 'localhost';

 

At this point  mysql is installed successfully's.

 

However, remote access or not, there are two places, the first is the database settings, and the second is the firewall. Generally can be directly connected to the database has been a success. But no ROOT privileges, if Rom, like me, must have been blocked by the firewall.

 

MYSQL database table can be controlled by visiting privileges, so we want to change about it, so we have a ROOT permissions.

 

 
  myql can remotely log  
 
  Setting mysql password  
 
  mysql>; USE mysql;      
mysql>; UPDATE user SET Password = PASSWORD ('newpassword') WHERE user = 'root';      
mysql>; FLUSH PRIVILEGES;      
1.2.3 allow remote login      
mysql-u root-p      
Enter Password:      
mysql> GRANT ALL PRIVILEGES ON *. * TO 'username' @ '%' IDENTIFIED BY 'password' WITH GRANT OPTION;      
after the completion can remotely manage mysql mysql-front up.      
set to boot      
chkconfig mysqld on  

windows environment to build Cocos2d

 

recently finally have time to make trouble satisfying their own things, Oh, it began to be a mobile game to play with kids.

 

must first develop a framework for the selected mobile terminal open source game framework seemingly small, this also asking many, the name simple Cocos2d-X, is Cocos2d domestic branches, buy a book, probably sweep look, framework supports IOS and Android, should meet the requirements, now began to engage!

 In fact, the development of Android

in linux better, but a business trip, do not bother to install the mirror and then the next, and on the use of existing Windows virtual machine right now to Cocos2d-X development environment set up process is simple record, and share with everyone.

 

Step 1

 

install windows. . . Install Oracle JDK. . . Installing Eclipse. . . Also omitted NK.

 

Step 2

 

install CDT, Cygwin

 

CDT is a C / C + + Development Tooling,

 

Click Eclipse-"help-" marketplace, search CDT, can be installed

 

 

cygwin is a windows platform running on unix simulation environment, brothers can http://www.cygwin.com/ Download the installation, with particular attention to the must install make Oh! specifically how loaded, you can search the Internet under.

 

Step 3

 

install ADT, Android SDK and NDK, these things are for Google Android developers must.

 

 

Here we must pay attention, the best online installation, download and install again in the fast, do not be under the offline package, easy to go wrong, remember!

 

Step 4

 

course, is to go to http://cocos2d.cocoachina.com/ Download Cocos2d-X's latest installation package, extract the installation! OK!

 

above is the basic process, but if you can get a full, then you should be very lucky. But the middle is sure to encounter problems, there are problems do not be afraid, we work together to solve!

 

In the following years, I will occasionally put some FAQ record, lest they make detours, thank you!

 

android layout and the layout of the property

 

set EditText is empty input box prompt information.

 

android: gravity
android: gravity attribute is limited to the contents of this view. For example, a button above the text. You can set the text in the view of the left, right, and other locations. In button example, android: gravity = "right" button above text is right

 

android: layout_gravity
android: layout_gravity is used to set up the view relative to the location of the parent view. For example, a button in linearlayout where you want the button on the left, right, and other locations can be set through this property. In button example, android: layout_gravity = "right" then button right

android: layout_alignParentRight

to make the right and the parent of the current control control is aligned to the right. This property value can only be true or false, default false.

 

android: scaleType:
android: scaleType is to control how the image resized / moved to the horses on the ImageView size. ImageView.ScaleType / android: scaleType meaning of the value difference:

 

CENTER / center at the original size picture centered, when the image length / width exceeding View the length / width, then the middle part of the picture shows the interception

 

CENTER_CROP / centerCrop scaled image size centered, makes the picture length (W) equal to or greater than the length of View (W)

 

CENTER_INSIDE / centerInside complete contents of the picture centered by a scaled-down size makes the picture or the original length / width equal to or less than the View's length / width

 

FIT_CENTER / fitCenter the picture proportionally expansion / reduction to View the width, centered

 

FIT_END / fitEnd the picture proportionally expansion / reduction to View the width of the lower part of the display in the View location

 

FIT_START / fitStart the picture proportionally expansion / reduction to View the width of the upper part of the display in the View location

 

FIT_XY / fitXY the picture? disproportionate expansion / reduction of the size of the display to the View

 

MATRIX / matrix matrix to draw dynamically shrink enlarged images to display.

 

** to note that, Drawable folder inside the picture naming is not capitalized.

Android project management issues svn code

 

using svn version control, svn itself does not identify which of the pass, which should not pass, which led to some of the things on the path (such as expanding jar path) have been uploaded, and when someone downloads After that path for this person may be completely absent, the project will compile problems. with eclipse svn plugin installed, you can not fall into the android projects have passed up.

 

Android project has the following contents of the documents do not need to add to version control:

 
      
  • bin directory
  •   
  • gen directory
  •   
  • . classpath file
  •   
  • . project file
  •  
 

order to mask them in eclipse, the need for such operations:

 
      
  1. Click on Window -> Preferences
  2.   
  3. Select Team -> Ignored Resources
  4.   
  5. Click on Add Pattern and enter "bin"
  6.   
  7. Click on Add Pattern and enter "target"
  8.   
  9. Click on Add Pattern and enter "m2-target"
  10.   
  11. Click on Add Pattern and enter "gen"
  12.   
  13. Click on Add Pattern and enter ". classpath"
  14.   
  15. Click on Add Pattern and enter ". project"
  16.   
  17. Click on Apply and then OK
  18.  
 

so submitted at a later time, these will automatically masked, not updated up.

 

Another problem is that each compilation, eclipse src directory will be something to consider to the bin where so. svn will go in, so that even if bin is masked, but still when the svn There are problems, solutions:

 

Menu - Project - Properties - Java Build Path - Source - xxx / src - Excluded, double-click or point to the right of the editing, Exclusion patterns add "** /. svn / **", so Eclipse ignored. svn directory.

mapred.jobtracker.plugins not start

In conf / mapred-site.xml about adding content in the system can start HUE provides plug-in, HUE manage JOB.




mapred.jobtracker.plugins <>
org.apache.hadoop.thriftfs.ThriftJobTrackerPlugin <>
Comma-separated list of jobtracker plug-ins to be activated.
<>
<>

jobtracker.thrift.address <>
0.0.0.0:9290 <>
<>

but the setting, the plug did not always start properly. Please enlighten master! Thank you!
------ For reference only -------------------------------------- -
depressed for a few days! Please help us to see.
------ For reference only -------------------------------------- -
resolved, as follows:
1, operating environment hadoop1.2.0, HUE 2.5.0

2, set the conf / mapred-site.xml



mapreduce.jobtracker.plugins <>
org.apache.hadoop.thriftfs.ThriftJobTrackerPlugin <>
Comma-separated list of jobtracker plug-ins to be activated.
<>
<>

jobtracker.thrift.address <>
0.0.0.0:9290 <>
<>

3, hue-plugins-2.5.0-SNAPSHOT.jar copied to $ HADOOP_HOME / lib

will be prompted to start jobtracker lack org.apache.hadoop.mapred.JobTrackerPlugin.
JobTrackerPlugin at Cloudera / com.cloudera.hadoop / hadoop-core / 0.20.2-320 exists, the code is as follows

============================================== =================
package org.apache.hadoop.mapred;

import org.apache.hadoop.util.ServicePlugin;

/ **
* JobTrackerPlugins are found in mapred.jobtracker.plugins, and are started
* and stopped by a PluginDispatcher during JobTracker start-up.
* /
abstract public class JobTrackerPlugin implements ServicePlugin {
abstract public void start (Object service);
abstract public void stop ();
}
============================================== =================

http://grepcode.com/file/repository.cloudera.com/content/repositories/releases/com.cloudera.hadoop/hadoop-core/0.20.2-320/org/apache/hadoop/mapred/ JobTrackerPlugin.java can download

copy to hadoop the src directory, compile HADOOP, in the build directory where you can get the new hadoop-core.jar, midterm will contain the missing JobTrackerPlugin.