2012-08-30 58 views
0

我們使用MessagePack 0.6.6對Java Grails的2.0在WebLogic11克(10.3)序列化字符串數據...MessagePack模板查找導致WebLogic中卡住線程?

public void serialize(Object object, OutputStream outputStream) 
    throws IOException { 
    byte[] bytes = MessagePack.pack(object); 
    outputStream.write(bytes); 
    outputStream.flush(); 
} 

我們在WebLogic中看到的問題是,大量阻塞線程的,所以我們向線程並發現一些線程卡在org.msgpack.template.TemplateRegistry.lookup(TemplateRegistry:198),請參閱下面的轉儲。我們確信我們的代碼沒有引入這個問題,因爲在上面的例子中,我們很清楚我們以線程安全的方式使用了MessagePack.pack()。看着 TemplateRegistry.java, line 198lookup()是同步的,但我們不確定它爲什麼導致卡住的線程。

 "[STUCK] ExecuteThread: 
    '1' for queue: 'weblogic.kernel.Default (self-tuning)'" id=43 idx=0xec tid=60 prio=1 alive, in native, blocked, daemon 

-- Blocked trying to get lock: org/msgpack/template/[email protected][fat lock] 
    at jrockit/vm/Threads.waitForUnblockSignal()V(Native Method) 
    at jrockit/vm/Locks.fatLockBlockOrSpin(Locks.java:1679)[optimized] 
    at jrockit/vm/Locks.lockFat(Locks.java:1780)[optimized] 
    at jrockit/vm/Locks.monitorEnterSecondStageHard(Locks.java:1312)[optimized] 
    at jrockit/vm/Locks.monitorEnterSecondStage(Locks.java:1259)[optimized] 
    at jrockit/vm/Locks.monitorEnter(Locks.java:2466)[inlined] 
    at jrockit/vm/Locks.monitorEnterForced(Locks.java:859)[optimized] 
    at jrockit/vm/RNI.c2java(JJJJJ)V(Native Method) 
    at jrockit/vm/Locks.monitorEnterUnmatched(Ljava/lang/Object;)V(Native Method) 
    at org/msgpack/template/TemplateRegistry.lookup(TemplateRegistry.java:198)[optimized]   
    at org/msgpack/MessagePack.write(MessagePack.java:195)[inlined] 
    at org/msgpack/MessagePack.pack(MessagePack.java:639)[inlined] 

回答

1

您應該使用打包器和拆包器,因爲this blog說。如果你每一次做太多,因爲新MessagePack()加載類

MessagePack msgpack = new MessagePack(); // singleton 
Packer packer = msgpack.createPacker(outputStream); // createPacker every time 
packer.write(object); 

下面的代碼可以產生perm gen memory error

MessagePack msgpack = new MessagePack(); 
byte[] bytes = msgpack.write(object); 
1

根據當前MessagePack JavaDoc靜態包(物體V)方法已被棄用,這是推薦的不是靜態的方法寫(對象)的使用。

用法示例:

MessagePack msgpack = new MessagePack(); 
byte[] bytes = msgpack.write(object); 

你能檢查寫入方法的使用是否解決了問題?

0

我相信這是沒有意義的手動創建打包機,只要MessagePack.write()會替你

公衆的byte []寫(T V)拋出IOException異常{ BufferPacker PK = createBufferPacker ();

我確實有你正在談論的燙髮錯誤,所以我在想的是在所有的應用程序中只使用一個MessagePack實例,這是否合理?

+0

看到李的回答,這是正確的。 – raffian

+0

@raffian我部分同意Lee的觀點,我只是聲稱在最新的消息包版本中,當您調用新的MessagePack()。write(someObject)方法時,默認情況下會創建新的消息包裝器,因此您不必顯式創建它足以在MessagePack實例上調用寫入方法。請檢查源代碼,如果您不同意此聲明,請告訴我我錯在哪裏。 – abovesun

+0

我相信你,我沒有說你錯了,只是說李的回答對我原來的問題已經足夠了。 – raffian