最近我們遊戲經常收到玩家投訴卡進度條的問題。而且後臺顯示執行佇列和CPU使用率異常高
根據呼叫的JDB分析出 使用xbean 時候會呼叫以下程式碼
在設定xmlobject 時候會有一個 GlobalLock.acquire();
當多執行緒併發設定xmlobject 時候造成互相等待這個GlobalLock 造成各個執行緒卡住,佇列執行效率不高
所以我們目前解決方法就是直接用string 拼接成XML 暫時不用xbean 的功能
- public final XmlObject set(XmlObject src)
- {
- if (isImmutable()) {
- throw new IllegalStateException("Cannot set the value of an immutable XmlObject");
- }
- XmlObjectBase obj = underlying(src);
- TypeStoreUser newObj = this;
- if (obj == null)
- {
- setNil();
- return this;
- }
- if (obj.isImmutable()) {
- set(obj.stringValue());
- }
- else {
- boolean noSyncThis = preCheck();
- boolean noSyncObj = obj.preCheck();
- if (monitor() == obj.monitor())
- {
- if (noSyncThis) {
- newObj = setterHelper(obj);
- }
- else {
- synchronized (monitor()) {
- newObj = setterHelper(obj);
- }
- }
- }
- else if (noSyncThis)
- {
- if (noSyncObj)
- {
- newObj = setterHelper(obj);
- }
- else
- {
- synchronized (obj.monitor()) {
- newObj = setterHelper(obj);
- }
- }
- }
- else
- {
- if (noSyncObj)
- {
- synchronized (monitor()) {
- newObj = setterHelper(obj);
- }
- }
- boolean acquired = false;
- try
- {
- GlobalLock.acquire();
- acquired = true;
- synchronized (monitor())
- {
- synchronized (obj.monitor())
- {
- GlobalLock.release();
- acquired = false;
- newObj = setterHelper(obj);
- }
- }
- }
- catch (InterruptedException e)
- {
- throw new XmlRuntimeException(e);
- }
- finally
- {
- if (acquired) {
- GlobalLock.release();
- }
- }
- }
- }
- return (XmlObject)newObj;
- }