views:

44

answers:

2

Hi dear community, I'm developing Java MIDI application.

And I have stuck with debugging of exception, which dispatching at the end of song. As I'm expecting: the application is playing and each time I'm checking the sequence tick position to represent it in application playback line, like as player.

So I want to know how could I get the source or the point where this Thread start running?

Below is an exception output:

Exception in thread "Thread-23" java.lang.IllegalStateException: Sequencer is not open
    at org.tritonus.share.midi.TSequencer.checkOpen(TSequencer.java:296)
    at org.tritonus.share.midi.TSequencer.stop(TSequencer.java:256)
    at org.tritonus.midi.device.java.JavaSequencer.run(JavaSequencer.java:291)
    at java.lang.Thread.run(Unknown Source)
+3  A: 

You could install a security manager which allows absolutely everything, but logs out when it's asked for permission to start a thread.

Or, you could provide a replacement Thread implementation and put it ahead of the one in rt.jar by using the bootclasspath options, and have this replacement Thread log its name and stacktrace in its constructor.

dty
The security manager idea is a really good idea - +1 for that!
aperkins
its hard to detect where does this Thread runs. The name is Thread-23 usually. Which security manager you have talked about? Could you provide please some snippets of how could I do this stuff? Thank you.
Eugene
The reason, that I don't want to determine what kind of Thread is this, I want to get know in which place its calling and by which caller?
Eugene
Yes, and the ideas I've given you will help you learn where the thread is constructed and by whom. You will have to implement your own security manager (it's very very simple, Google it) if you wanted to try the first idea. For the second idea, just copy the source of Thread.java and recompile it with some extra logging and add it to the bootclasspath.
dty
So will debug version of rt.jar will help me to find caller point of Thread? Cause I don't want to be pointed just to source of run method.
Eugene
When the SecurityManager is asked if a thread can start, you can get a stack trace and print that out at that location, as @dty is suggesting in his comment. You can do that by doing Thread.getCurrentThread().getStackTrace() or Thread.getCurrentThread().printStackTrace() [syntax may be slightly off - doing it from memory]
aperkins
@aperkins It seems to be that this run method is inside of 3rd party jar. So how could I call your methods outside of that class?
Eugene
*sigh* *headdesk*
dty
@dty what does it mean?
Eugene
It means I'm banging my head on the desk! You're not reading what me or aperkins are writing. You're just expecting someone to tell you where the problem is, and nobody can to that. You will need to do some investigation of your own system on your own. I've suggested two techniques that might help with that investigation.
dty
@dty Nope your dear dty, I'm trying to get all available solutions, because I'm not able to spend a lot of time to test all methods, so just looking for good solution. That's all, dear dty.
Eugene
dty is correct however - both of those solutions are good, and will likely be the best that you are going to get. I would look up securityManager and read about it, because that is how I would approach the problem you are facing, based on what you have described.
aperkins
the way with debug version of rt.jar from latest jdk - didn't help.
Eugene
Nobody except you mentioned using a debug version of rt.jar - whatever one of those is. I said, recompile Thread.java with extra logging in the constructor and put it on the bootclasspath. And I said it at least three times now.
dty
How should I do this recompiling? I didn't get your solution. Sorry. Explain please. Thank you.
Eugene
+1  A: 

org/tritonus/midi/device/java/JavaSequencer.java has the following code:

protected void openImpl()
    {
            ...
            m_thread = new Thread(this);
            ...
            m_thread.start();
    }

So that's one place to look for (but that answers only the specific case, not the general question how to find out where a thread is started in general).

There are also other places in the same class where this.start() is called: in setSequence(..) and setTickPosition(..). There could be calls to start() outside the class however.

Andre Holzner
yes sounds good, but regards eclipse debugger this thread appears only at the end of song playback. Thats I want to determine why this appearing and how to try/catch it? This exception dispatching only when playback is finished. But not from code I wrote.
Eugene
From the error message and stack trace it looks like you're closing the sequencer once too often ? Maybe you don't have to close it by hand, when the thread stops (the program ends), this seems to happen automatically ?!
Andre Holzner
I don't stop it manually, but I'm checking each time the ticker position, in all other cases application don't touching sequencer except play/pause function.
Eugene
By the way, Tritonus is open source. I guess you could download the source and add it as a project your project depends on. So you could set breakpoints at various places in Tritonus and look at stack traces.
Andre Holzner
I tried, but jar I'm using is 2009 year, and there are sources in CVS, and I looked on it, but find whole sources, and have no idea how to separate a java sequencer part from there.
Eugene