如何将java解析为javascript调用? Applet正在等待!

时间:2011-07-24 02:46:08

标签: java javascript google-chrome liveconnect

我无法避免我的小程序中的零星崩溃,这似乎是由一个等待自己的线程引起的。奇怪的是,这似乎只发生在谷歌浏览器中。

30秒阅读:

  • Applet.methodA()调用JSObject.javascriptMethod()
  • javascriptMethod()进行Applet.methodB()调用
  • Applet.methodB()等待Applet.methodA()释放它的锁定,这种情况从未发生..

我尝试过的事情:

  • 在javascriptMethod中使用setTimeout。那里没有运气。
  • 使用JSObject.eval()而不是JSObject.call()

也可能: 我完全误解了线程转储。这是为了检查。

我的理解:

  1. 音序器线程调用applet.notifyPosition
  2. notifyPosition调用javascript方法
  3. javascript方法调用applet.pause
  4. applet.pause需要锁定音序器,但不能因为它忙于调用notifyposition ..

    "Java Sound Sequencer" prio=8 tid=0x189de400 nid=0x86c in Object.wait() [0x1c6ae000]
       java.lang.Thread.State: TIMED_WAITING (on object monitor)
            at java.lang.Object.wait(Native Method)
            - waiting on <0x099c50e0> (a java.lang.Object)
            at com.sun.media.sound.RealTimeSequencer$PlayThread.stop(Unknown Source)
            - locked <0x099c50e0> (a java.lang.Object)
            - locked <0x099c50e8> (a com.sun.media.sound.RealTimeSequencer$PlayThread)
            at com.sun.media.sound.RealTimeSequencer.implStop(Unknown Source)
            at com.sun.media.sound.RealTimeSequencer.stop(Unknown Source)
            - locked <0x099c8ca8> (a com.sun.media.sound.RealTimeSequencer)
            at net.alphatab.midi.MidiPlayer.pause(Unknown Source)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at sun.plugin.javascript.JSInvoke.invoke(Unknown Source)
            at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at sun.plugin.javascript.JSClassLoader.invoke(Unknown Source)
            at sun.plugin2.liveconnect.JavaClass$MethodInfo.invoke(Unknown Source)
            at sun.plugin2.liveconnect.JavaClass$MemberBundle.invoke(Unknown Source)
            at sun.plugin2.liveconnect.JavaClass.invoke0(Unknown Source)
            at sun.plugin2.liveconnect.JavaClass.invoke(Unknown Source)
            at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$DefaultInvocationDelegate.invoke(Unknown Source)
            at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$3.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo.doObjectOp(Unknown Source)
            at sun.plugin2.main.client.LiveConnectSupport.doObjectOp(Unknown Source)
            at sun.plugin2.main.client.MessagePassingJSObject.waitForReply(Unknown Source)
            at sun.plugin2.main.client.MessagePassingJSObject.call(Unknown Source)
            at net.alphatab.midi.MidiPlayer.notifyPosition(Unknown Source)
            at net.alphatab.midi.MidiPlayer.access$200(Unknown Source)
            at net.alphatab.midi.MidiPlayer$1.controlChange(Unknown Source)
            at net.alphatab.midi.TickNotifierReceiver.send(Unknown Source)
            at com.sun.media.sound.AbstractMidiDevice$TransmitterList.sendMessage(Unknown Source)
            - locked <0x0982d8e8> (a java.util.ArrayList)
            at com.sun.media.sound.RealTimeSequencer$DataPump.dispatchMessage(Unknown Source)
            at com.sun.media.sound.RealTimeSequencer$DataPump.pump(Unknown Source)
            - locked <0x09a56ae8> (a com.sun.media.sound.RealTimeSequencer$DataPump)
            at com.sun.media.sound.RealTimeSequencer$PlayThread.run(Unknown Source)
            at java.lang.Thread.run(Unknown Source)
    

1 个答案:

答案 0 :(得分:3)

在这里,我们看到看起来像问题的部分:

"Java Sound Sequencer" prio=8 tid=0x189de400 nid=0x86c in Object.wait() [0x1c6ae000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x099c50e0> (a java.lang.Object)
        at com.sun.media.sound.RealTimeSequencer$PlayThread.stop(Unknown Source)
        - locked <0x099c50e0> (a java.lang.Object)

这个等待<0x099c50e0> 并不意味着该线程等待获取锁定,但它有锁定,并在此对象上调用wait(),这意味着它暂时取消锁定并等待其他线程在此同一对象上调用.notify().notifyAll()

因此,此单个堆栈跟踪不会显示死锁。

当然,可能是从applet到JavaScript以及从JavaScript返回到applet的实际调用都在不同的线程上,这可能会显示您描述的行为。但是你在这里的堆栈跟踪似乎并没有表明这一点(我认为alphatab类是你的)。

问题很简单,没有人因某种原因打电话给notify()。也许有一些同步错误,所以通知实际上是在等待之前。或者其他一些线程在通知之前等待其他锁(这将是一个真正的死锁)。