Back from the grave.
I moved EVERYTHING from Windows XP 32 to Windows 7 64 bit. This has proven to be such a black hole that... well, everything fell into it.
It's weird that that I cannot find a guide on porting an application. There are so many deprecated Win32 functions that need to be replaced with x64 counterparts. But a quick google does not find a tutorial on what to do, and what to avoid.
Well, we will see.
Wednesday, April 7, 2010
Wednesday, September 30, 2009
Ant Task to generate GWT Classes and servlets
Yet Another Ant Task.
I made a task which given:
A source dir, a source classpath, and destination dir,
A series of source interfaces and a new GWT name,
My task will generate all the GWT plumbing. Namely the Service interface, the ServiceAsync interface, and a Servlet Implementation. If you specify a delegate, the the servlet will implement the interface by calling the methods in the delegate.
Pretty sweet.
I learned a lot about how "Generic" info about classes can be obtained through the reflection API. You might think that all the type parameter stuff is erased, a-la
Section 4.6 of the Java spec., but it is all there in the class, available through reflection. On the other hand, this leads to a paradox, because the it's not supposed to be there.
I made a task which given:
A source dir, a source classpath, and destination dir,
A series of source interfaces and a new GWT name,
My task will generate all the GWT plumbing. Namely the Service interface, the ServiceAsync interface, and a Servlet Implementation. If you specify a delegate, the the servlet will implement the interface by calling the methods in the delegate.
Pretty sweet.
I learned a lot about how "Generic" info about classes can be obtained through the reflection API. You might think that all the type parameter stuff is erased, a-la
Section 4.6 of the Java spec., but it is all there in the class, available through reflection. On the other hand, this leads to a paradox, because the it's not supposed to be there.
For example, let's say you have:
public interface Foo{
List<String> someMethod();
}
The compiler halts with an error if you try to implement Foo with this class:
public class Bar implements Foo{
List<String> someMethod(){return new ArrayList<String>();}
}
Because the type parameter of the returned List<String> has been "erased", and the return type in the interface is actually just List.
But if you were using reflection to generate class source you would still find the <String> type parameter. So to get your implementation to compile, you must discard the Type info.
At least that's the way it seems to work :)
Thursday, September 24, 2009
How to make JNI apps reloadable
JNI has this annoying "feature" , that makes is very difficult to run an application ( or ant task, or whatever) that loads a native library.
When you load a class ( lets call it Foo ) that loads loads a DLL, loadLibrary is called on the ClassLoader that loaded Foo.
If you try to load the Foo class again, and the library is still loaded, then loadLibrary will fail with a java.lang.UnsatisfiedLinkError.
The DLL that Foo loaded will NOT be unloaded when Foo is garbage collected. The DLL will not be unloaded until the ClassLoader, and all the other classes that were loaded with Foo's ClassLoader are garbage collected. If that ClassLoader is the System ClassLoader, it will never be unloaded while the JVM is running.
This makes it an exceptional pain to try and re-deploy an app to an application server.
There is a lot of whining about this, and a lot of bad advice. So here is a WORKING solution.
A) All the classes that load native libraries (JNI clients) should implement interfaces for their use.
B) All the other classes should ONLY reference the interfaces, never the classes themselves.
C) JNI client classes must be loaded by a separate classloader then the other classes.
D) The instances of the JNI client classes must be instantiated by reflection, not by directly calling a class’s constructor. This prevents the class being loaded by a non-JNI ClassLoader
To accomplish this, I created a VolitileFactory class, that subclasses URLClassLoader. It has a makeInstance method, which loads the JNI client classes, and invokes the correct constructor via reflection. The VolitileFactory instance is a field of the Anchor class. Anchor has static methods to obtain implementers of the JNI client’s interfaces. Anchor holds the only reference to the factory. When the app shuts down, that reference is deleted, System.gc() is called, and the libraries unload.
When you load a class ( lets call it Foo ) that loads loads a DLL, loadLibrary is called on the ClassLoader that loaded Foo.
If you try to load the Foo class again, and the library is still loaded, then loadLibrary will fail with a java.lang.UnsatisfiedLinkError.
The DLL that Foo loaded will NOT be unloaded when Foo is garbage collected. The DLL will not be unloaded until the ClassLoader, and all the other classes that were loaded with Foo's ClassLoader are garbage collected. If that ClassLoader is the System ClassLoader, it will never be unloaded while the JVM is running.
This makes it an exceptional pain to try and re-deploy an app to an application server.
There is a lot of whining about this, and a lot of bad advice. So here is a WORKING solution.
A) All the classes that load native libraries (JNI clients) should implement interfaces for their use.
B) All the other classes should ONLY reference the interfaces, never the classes themselves.
C) JNI client classes must be loaded by a separate classloader then the other classes.
D) The instances of the JNI client classes must be instantiated by reflection, not by directly calling a class’s constructor. This prevents the class being loaded by a non-JNI ClassLoader
To accomplish this, I created a VolitileFactory class, that subclasses URLClassLoader. It has a makeInstance method, which loads the JNI client classes, and invokes the correct constructor via reflection. The VolitileFactory instance is a field of the Anchor class. Anchor has static methods to obtain implementers of the JNI client’s interfaces. Anchor holds the only reference to the factory. When the app shuts down, that reference is deleted, System.gc() is called, and the libraries unload.
Saturday, September 12, 2009
Summer break is over, back to the Toy.
I re-implemented the event loop and the event objects to be in Java instead of native code.
There is a Java EventMachine. A client uses getTheEventMachine to get only instance. It maintains a timer and a FIFO blocking queue of SimpleEvents. SimpleEvents are added to the queue by the addEvent method of EventMachine. At the preset interval, the queue is locked, and the SimpleEvents in it are dispatched to processEvent in the UpperDeck one at a time, until they are all processed, or until a set amount of time has passed. Then, dispatching ceases and the queue is unlocked. processEvent in UpperDeck processes the event, and in a finally clause, calls the delete method of the event.
This system is used by native code via a C++ JEventMachineConnector class. This maintains a global reference to a thread in the EventMachine where addEvent executes. So when addEvent is called on JEventMachineConnector, it joins the Java thread, calls addEvent on EventMachine, and upon completion, detaches from the thread.
The SimpleEvent interface is an immutable collection of three properties: source, type and message, and a delete method. However the implementation of SimpleEvent is not simple. An implementation consists of a Java object SimpleEventJavaImpl, and it’s native shadow. The Java object implements SimpleEvent, exports a delete method, and maintains a pointer to the native shadow object. This delete method is actually implemented natively. Upon garbage collection, if the native resources have not been freed, SimpleEventJavaImpl calls its own delete method. The native shadow object maintains a link to the Java object, and native versions of the initial value of the properties of the SimpleEvent. It also implements logic to create SimpleEventJavaImpl objects from the native side. The hairiness of SimpleEvent implementation comes from the logic to instantiate one from the native or Java side, and then to delete all native resources.
The Toy also grew much hair implementing Java<->Native exception handling, and other error management. I learned far more then I wanted to know about C++ templates, Unicode on Windows, and why the C++ preprocessor is pure freaking EVIL.
There is a Java EventMachine. A client uses getTheEventMachine to get only instance. It maintains a timer and a FIFO blocking queue of SimpleEvents. SimpleEvents are added to the queue by the addEvent method of EventMachine. At the preset interval, the queue is locked, and the SimpleEvents in it are dispatched to processEvent in the UpperDeck one at a time, until they are all processed, or until a set amount of time has passed. Then, dispatching ceases and the queue is unlocked. processEvent in UpperDeck processes the event, and in a finally clause, calls the delete method of the event.
This system is used by native code via a C++ JEventMachineConnector class. This maintains a global reference to a thread in the EventMachine where addEvent executes. So when addEvent is called on JEventMachineConnector, it joins the Java thread, calls addEvent on EventMachine, and upon completion, detaches from the thread.
The SimpleEvent interface is an immutable collection of three properties: source, type and message, and a delete method. However the implementation of SimpleEvent is not simple. An implementation consists of a Java object SimpleEventJavaImpl, and it’s native shadow. The Java object implements SimpleEvent, exports a delete method, and maintains a pointer to the native shadow object. This delete method is actually implemented natively. Upon garbage collection, if the native resources have not been freed, SimpleEventJavaImpl calls its own delete method. The native shadow object maintains a link to the Java object, and native versions of the initial value of the properties of the SimpleEvent. It also implements logic to create SimpleEventJavaImpl objects from the native side. The hairiness of SimpleEvent implementation comes from the logic to instantiate one from the native or Java side, and then to delete all native resources.
The Toy also grew much hair implementing Java<->Native exception handling, and other error management. I learned far more then I wanted to know about C++ templates, Unicode on Windows, and why the C++ preprocessor is pure freaking EVIL.
Wednesday, June 24, 2009
Passing wrapped C++ objects to Java
In the Toy, C++ code generates an Event, and passes it to Java for processing.
The flow is
Client class (Cclient) creates C++ SimpleEvent (launchEvent)
cClient calls getJEMConnector()->addEvent(*launchEvent);
addevent attaches the C++ thread to the JVM,
creates a Java SimpleEvent wrapper (jSimpleEvent)
calls addEvent(jSimpleEvent) on the Java EventMachine
An now it's up to Java to further handle the event.
Object life cycles are tricky when there are multiple threads. Calling a Java constructor from C++ is no fun because of the weird signature stuff, i.e. "", "(JZ)V" to call the constructor that takes a (long)pointer and a boolean argument.
Then there is Local/Global reference issue. DeleteGlobalRef must be called within C++, before the object is destroyed, on some JavaENV, that should have been cached earlier. This is on top of the memory management problem, as discussed earlier.
I'm going to do some memory leak checks now. I'll be surprised if there are none, because nowhere in C++ do I call DeleteGlobalRef for the SimpleEvent wrapper.
The flow is
Client class (Cclient) creates C++ SimpleEvent (launchEvent)
cClient calls getJEMConnector()->addEvent(*launchEvent);
addevent attaches the C++ thread to the JVM,
creates a Java SimpleEvent wrapper (jSimpleEvent)
calls addEvent(jSimpleEvent) on the Java EventMachine
An now it's up to Java to further handle the event.
Object life cycles are tricky when there are multiple threads. Calling a Java constructor from C++ is no fun because of the weird signature stuff, i.e. "
Then there is Local/Global reference issue. DeleteGlobalRef must be called within C++, before the object is destroyed, on some JavaENV, that should have been cached earlier. This is on top of the memory management problem, as discussed earlier.
I'm going to do some memory leak checks now. I'll be surprised if there are none, because nowhere in C++ do I call DeleteGlobalRef for the SimpleEvent wrapper.
Monday, June 22, 2009
Allocate objects from the JVM
My Event and threading mechanics are all going to be in Java. But I still create some events from C++, wrap them in a Java class, and add them to the queue. When they are processed, I destroy them, and clear the queue, so there are no references.
This created a memory management problem. The "new" was in c++, but the "delete" is in Java. So I ended up overriding the new and delete operators, and having them use the JVM for resources. This seems to work.
This created a memory management problem. The "new" was in c++, but the "delete" is in Java. So I ended up overriding the new and delete operators, and having them use the JVM for resources. This seems to work.
Saturday, June 20, 2009
Note to self, varargs stuff are all macros
So, I leared how to use varargs.
Not just declaring a varargs function and getting the arguments.
No, the trick was to get a va_list and pass it on to something like vswprintf. My problem was that whenever I had a number in my va_list, it would get scrambled in the output.
The thing to learn was that all the varargs stuff is just pointer arithmetic on a single char *, obfuscated by macros. The macros create hidden variables, which change state on every use of va_start(), va_arg(), va_list(). So, you can't use any of the arguments passed to your function if you want to pass that va_list on to another function. If you ever call va_arg(), you must reset everything bay calling va_end(), va_start() before you pass the va_list.
It's pretty rotten that
A) None of this stuff follows macro naming conventions, i.e VA_START
B) The side effects of using va_start and va_args are undocumented, not even on faqs or forums.
Not just declaring a varargs function and getting the arguments.
No, the trick was to get a va_list and pass it on to something like vswprintf. My problem was that whenever I had a number in my va_list, it would get scrambled in the output.
The thing to learn was that all the varargs stuff is just pointer arithmetic on a single char *, obfuscated by macros. The macros create hidden variables, which change state on every use of va_start(), va_arg(), va_list(). So, you can't use any of the arguments passed to your function if you want to pass that va_list on to another function. If you ever call va_arg(), you must reset everything bay calling va_end(), va_start() before you pass the va_list.
It's pretty rotten that
A) None of this stuff follows macro naming conventions, i.e VA_START
B) The side effects of using va_start and va_args are undocumented, not even on faqs or forums.
Wednesday, June 17, 2009
Debugging's "attach to process" broke.
Somehow,
Attach to process from "java.exe" does not work since I reinstalled everything.
"java.exe" gets expanded to the the full path, Q:\sdk\jdk1.6.0_14\bin\java.exe
Which does not match the process in the process list, as launched by Netbeans.
It used to work, but now instead of just hitting f5, I must use two menus, search and click. Visual Studio is simply terrible. How can a product with so many iterations stink so bad?
...
Anyway the trick to getting f5 to work again was to use
Q:\sdk\jdk1.6.0_14\jre\bin\java.exe
Note the "jre" in there.
Sigh. For whatever reason , MSVC stores this debugging info on a
per-user level, with not even a shadow in the project's .vsproj XML file.
So there is no easy way to store this setting with the project.
Attach to process from "java.exe" does not work since I reinstalled everything.
"java.exe" gets expanded to the the full path, Q:\sdk\jdk1.6.0_14\bin\java.exe
Which does not match the process in the process list, as launched by Netbeans.
It used to work, but now instead of just hitting f5, I must use two menus, search and click. Visual Studio is simply terrible. How can a product with so many iterations stink so bad?
...
Anyway the trick to getting f5 to work again was to use
Q:\sdk\jdk1.6.0_14\jre\bin\java.exe
Note the "jre" in there.
Sigh. For whatever reason , MSVC stores this debugging info on a
per-user level, with not even a shadow in the project's .vsproj XML file.
So there is no easy way to store this setting with the project.
Tuesday, June 16, 2009
Mercurial Trap
I really like mercurial.
One of the great things is that you have local and "other" (remote) repositories. You can happily check in and track changes locally, then later, push your changesets to the remote repository.
But this leads to a usability issue. You can *forget* to push your changes, and you can neglect to have a remote repo at all.
This just happened to the .swg I made for SWIG. When my drive was corrupted, I lost the work I had done. In this case it was only a few minutes to re-create it. But it could have been bad.
Mercurial does allow practically unlimited extensions, so I could make mercurial automatically create a remote repo when I create a local one. I could also make some kind of nag feature for pushing every day or something.
One of the great things is that you have local and "other" (remote) repositories. You can happily check in and track changes locally, then later, push your changesets to the remote repository.
But this leads to a usability issue. You can *forget* to push your changes, and you can neglect to have a remote repo at all.
This just happened to the .swg I made for SWIG. When my drive was corrupted, I lost the work I had done. In this case it was only a few minutes to re-create it. But it could have been bad.
Mercurial does allow practically unlimited extensions, so I could make mercurial automatically create a remote repo when I create a local one. I could also make some kind of nag feature for pushing every day or something.
Build environment
Just for reference, here are the tools and libraries that need to be installed.
*** Tools ***
Netbeans 6.5+
MSVC 2008
Ant 1.7+
CUDA 2.2
Mercurial 1.2+
swigwin (customized!!)
boost-build
*** Libraries ***
jargs
jinvoke
CUDA 2.2 SDK
freeglut (customized!!)
boost_1_38_0 (with static+multithreaded+debug compilation)
*** Projects ***
filesystemmanagement
JNIAntTasks
*** Tools ***
Netbeans 6.5+
MSVC 2008
Ant 1.7+
CUDA 2.2
Mercurial 1.2+
swigwin (customized!!)
boost-build
*** Libraries ***
jargs
jinvoke
CUDA 2.2 SDK
freeglut (customized!!)
boost_1_38_0 (with static+multithreaded+debug compilation)
*** Projects ***
filesystemmanagement
JNIAntTasks
Friday, June 12, 2009
System woes.
Diskkeeper corrupted my filesystem.
Prudence means that I have a remote repository, and that I've only lost a day of changes, but that assumes that ONLY my local repo is damaged, and not any of the other files (binaries!!!) on that volume. I expect that there is corruption all over this drive, and I must reinstall EVERYTHING. This sucks.
I am looking a one hell of a lot of stuff to download and install.
The week of work that I have not posted about was a new Java based event system. To get this to work, I installed SWIG, a general purpose c/c++ -> other language integration tool. But strangely enough, SWIG does not support unicode for Java, and so I had to mess around for a day creating a SWING typemapping file. ick!
It works, but then my filesystem was corrupted by Diskeeper.
Prudence means that I have a remote repository, and that I've only lost a day of changes, but that assumes that ONLY my local repo is damaged, and not any of the other files (binaries!!!) on that volume. I expect that there is corruption all over this drive, and I must reinstall EVERYTHING. This sucks.
I am looking a one hell of a lot of stuff to download and install.
The week of work that I have not posted about was a new Java based event system. To get this to work, I installed SWIG, a general purpose c/c++ -> other language integration tool. But strangely enough, SWIG does not support unicode for Java, and so I had to mess around for a day creating a SWING typemapping file. ick!
It works, but then my filesystem was corrupted by Diskeeper.
Thursday, June 4, 2009
Now I need a whole new event-loop.
ImageFactory works.
I had to customize FreeGlut to share the HWND window handle that it creates when it opens the main Window. From that I can call wglCreateContext and make that rendering context current. I'm not sure how to get OpenGL rendering context without ever opening an Window....
Anyway, ImageFactory is now dependent on data that must be requested from the UpperDeck, but I've run into insurmountable system-messaging bugs.
Currently, the Toy uses FreeGlut to manage windowing, keyboard, etc.
I am now convinced that the main-loop of Glut breaks Swing, and maybe all Java events. I suspect that the system messages are held up somehow, and are only passed along after the "main window" closes.
The irony is that I'm not going to use the FreeGlut main loop, Swing, or even a screen window. But for testing etc, I need a GUI for control and communication.
So I have to dive into replacing the main loop before I wanted to.
Dang.
Oh, and there are still bogus exceptions thrown from within the Nvidia drivers at "exit". These propagate up and crash the JVM.
Dang again.
I had to customize FreeGlut to share the HWND window handle that it creates when it opens the main Window. From that I can call wglCreateContext and make that rendering context current. I'm not sure how to get OpenGL rendering context without ever opening an Window....
Anyway, ImageFactory is now dependent on data that must be requested from the UpperDeck, but I've run into insurmountable system-messaging bugs.
Currently, the Toy uses FreeGlut to manage windowing, keyboard, etc.
I am now convinced that the main-loop of Glut breaks Swing, and maybe all Java events. I suspect that the system messages are held up somehow, and are only passed along after the "main window" closes.
The irony is that I'm not going to use the FreeGlut main loop, Swing, or even a screen window. But for testing etc, I need a GUI for control and communication.
So I have to dive into replacing the main loop before I wanted to.
Dang.
Oh, and there are still bogus exceptions thrown from within the Nvidia drivers at "exit". These propagate up and crash the JVM.
Dang again.
Friday, May 22, 2009
Bogged down in driver bugs
I have not made progress in the thread context stuff because of driver crash bugs.
Luckily, CUDA 2.2 just came out.
So I installed the new drivers, toolkit and SDK, and ported my source code.
Things are now MUCH better. Even though there are still many "first chance" exceptions, at least I don't have the same show-stopping crash bugs.
I can now return to the re-writing ImageFactory to have its own GLContext.
Luckily, CUDA 2.2 just came out.
So I installed the new drivers, toolkit and SDK, and ported my source code.
Things are now MUCH better. Even though there are still many "first chance" exceptions, at least I don't have the same show-stopping crash bugs.
I can now return to the re-writing ImageFactory to have its own GLContext.
Tuesday, May 5, 2009
OpenGL is very particular about threads.
So, it turns out that every thread that uses OpenGL needs its own rendering context.
Currently, the thread running in the ImageFactory class does not have one. Let's call that thread imageProducerThread.
This means that I must either:
Join the launch thread from imageProducerThread,
Create a new context on imageProducerThread,
Move all the OpenGL stuff to imageProducerThread,
All of these require lots of re-writing....
Sigh, I guess moving everything is the best solution.
Dang.
Currently, the thread running in the ImageFactory class does not have one. Let's call that thread imageProducerThread.
This means that I must either:
Join the launch thread from imageProducerThread,
Create a new context on imageProducerThread,
Move all the OpenGL stuff to imageProducerThread,
All of these require lots of re-writing....
Sigh, I guess moving everything is the best solution.
Dang.
Friday, April 17, 2009
Ready to learn about glReadPixels, DIBs and GTK+
My event infrastructure seems complete and functional enough.
I tripped up by putting calls to java.util.Logging in the event thread. It would be nice if Sun had documented that those methods are not thread safe.
Now I need to get my rendered images out of the CUDA environment and into a bitmap.
I Posted on the openGL forum and got some hints, so here I go!
I tripped up by putting calls to java.util.Logging in the event thread. It would be nice if Sun had documented that those methods are not thread safe.
Now I need to get my rendered images out of the CUDA environment and into a bitmap.
I Posted on the openGL forum and got some hints, so here I go!
Friday, April 10, 2009
Ignorance and distraction.
The problem was that alock did NOT drop out of scope in the code as written.
alock was also defined out of the if block, and only gets its value in the if block.
I deleted the declaration and now the line
boost::mutex::scoped_lock alock(_mutex);/*Yes Charlweed, lock is an INSTANCE.*/
Works as expected.
alock was also defined out of the if block, and only gets its value in the if block.
I deleted the declaration and now the line
boost::mutex::scoped_lock alock(_mutex);/*Yes Charlweed, lock is an INSTANCE.*/
Works as expected.
Behold! The power of ignorance
It's looking like the bug has nothing to do with JNI.
I don't really know much about C++ threading, the Boost APIs or even STL. So I don't yet see the fundamental flaw in this event loop:
It does not work at all. Because this is running on a separate thread, I want it to flow forever, PAUSING only when it cannot get a lock on the mutex. I'm not sure what is really happening, but it looks like the other thread blocks permanently after the _eventList gains an item.
Dang.
I don't really know much about C++ threading, the Boost APIs or even STL. So I don't yet see the fundamental flaw in this event loop:
while(true){
if(!_eventList.empty()){
boost::mutex::scoped_lock alock(_mutex);/*Yes Charlweed, lock is an INSTANCE.*/
for(eventIterator =_eventList.begin();eventIterator != _eventList.end();eventIterator++){
/* pop the event off of the queue */
queuedEvent = &(*eventIterator);// This line really bugs me.
//processEvent(queuedEvent,javaThreadEnv,theUpperDeck);
}
_eventList.clear();
}
}
It does not work at all. Because this is running on a separate thread, I want it to flow forever, PAUSING only when it cannot get a lock on the mutex. I'm not sure what is really happening, but it looks like the other thread blocks permanently after the _eventList gains an item.
Dang.
Threading Bug?
As I said before, I created functionality where the DLL can post a string to the Java app. My problem is that if I log that message with the java logger, or try to show it on the screen in Swing, the message:
a) Fails to show the string.
b) Stops the flow of control.
I’m not saying things like “deadlock”, "blocks" or even “hangs” because I don’t really know what is going on.
Within my display method in Java,
I tried starting a new thread but that fails too.
Now I'm going to read the chapters on “Monitors” and “Exceptions” to see what exotic BS might be going on.
Speaking of exceptions, I found that yes indeed, the native code is completely swallowing my exceptions from within Java. So the bug above is really hard to diagnose.
a) Fails to show the string.
b) Stops the flow of control.
I’m not saying things like “deadlock”, "blocks" or even “hangs” because I don’t really know what is going on.
Within my display method in Java,
SwingUtilities.invokeAndWaitand
SwingUtilities.invokeLatercompletely hang, both with threads and runnables.
I tried starting a new thread but that fails too.
Now I'm going to read the chapters on “Monitors” and “Exceptions” to see what exotic BS might be going on.
Speaking of exceptions, I found that yes indeed, the native code is completely swallowing my exceptions from within Java. So the bug above is really hard to diagnose.
Thursday, April 2, 2009
The important part is...
So yeah, my native code can now communicate with the Java App :)
Yea!
The way do do this is to call any method of
from within the switch block of
Right now I have merely hard-coded a call to
But I could register listeners on UpperDeck, and propagate events out from there.
I'll wait on that, because I don't what I want to transmit out of the DLL, or who will want to listen.
Yea!
The way do do this is to call any method of
com.hymerfania.mandelbrotbridge.UpperDeck
from within the switch block of
MandelbrotLib::EventMachine::processEvent
Right now I have merely hard-coded a call to
UpperDeck.helloWorld(String message)
But I could register listeners on UpperDeck, and propagate events out from there.
I'll wait on that, because I don't what I want to transmit out of the DLL, or who will want to listen.
Event model works.
It turns out that SwingWorker is not enough to run native code.
I had a terrible time figuring out why SwingUtilities.invoke* would not launch my runnable.
What I was doing was
MainThread runs starting the mainApp
SwingThread runs gui
SwingworkerThread runs some setup code but...
propertyChangeThread runs the nativeDLL
The nativeDLL calls back into java. That java code attempts to use java.awt.EventQueue.invokeLater to make changes to the GUI. Well, it seems that you cant use EventQueue methods from the thread that propertyChanges are on. Note that whatever the propertyChangeThread actually is, it is NOT the Swing Event Dispatch thread. I checked for that.
Anyway, I created and started a completely new thread to run the DLL code, and everything seems to work much better.
I had a terrible time figuring out why SwingUtilities.invoke* would not launch my runnable.
What I was doing was
MainThread runs starting the mainApp
SwingThread runs gui
SwingworkerThread runs some setup code but...
propertyChangeThread runs the nativeDLL
The nativeDLL calls back into java. That java code attempts to use java.awt.EventQueue.invokeLater to make changes to the GUI. Well, it seems that you cant use EventQueue methods from the thread that propertyChanges are on. Note that whatever the propertyChangeThread actually is, it is NOT the Swing Event Dispatch thread. I checked for that.
Anyway, I created and started a completely new thread to run the DLL code, and everything seems to work much better.
Subscribe to:
Posts (Atom)