Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-29-2008, 10:29 PM
Member
 
Join Date: Jan 2008
Location: Oklahoma
Posts: 1
cornercuttin is on a distinguished road
data from the main/GUI thread to another runnin thread...
hello all,

it has been a long, long time since i have done java work, and even longer since i have done threading work in java, so i am a little rusty, and after a few hours of research and tinkering, i can't seem to figure something out (this would be easy with pointers...).

basically, i am writing some software that has a C based background process, but with a Java front end (don't ask why. an existing code-base made it a necessity). the java GUI is extremely simple; basically just drop down boxes, in which the values were being written to text files and picked up by the C. now we are going to get rid of the text files and go with sockets.

basically, the java only needs 2 threads. the GUI thread and then the thread running the socket stuff. the socket thread is running as a server, and the C will be running as a client. this is how it had to work because this is basically an extension to the C code, and it cannot spawn another thread, nor sit in a wait state forever.

all i need to know is how to continuously pass information from the GUi thread to the socket thread. basically, there are a few objects that the data resides in (the data that is being entered by the GUI), and i need to pass this stuff to the socket thread as it is updated (every time a drop down box is clicked, the updated data needs to go to the socket thread).

this is an interesting concept, considering the socket thread is in a "wait" state, meaning the line "Socket connectionSocket = myServerSocket.accept();" puts this thread in a "wait" state as is. so data in the socket thread isn't getting updated as it should; it is only getting updated when it receives another connection and finally gets out of that "wait" state.

anyone have any clues? if you had a Java Server running and in its "wait" state, how do you dynamically update information that it is supposed to send to the client?

thanks a ton for any help whatsoever.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-23-2008, 07:38 PM
danielstoner's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 117
danielstoner is on a distinguished road
You could instantiate an Event (you have to define the class) containing the status of the GUI every time the GUI changes, on the GUI thread. The same GUI thread will store these events in a queue of events (synchronized). When the socket thread wakes up will process the events in the queue. On the socket thread you can implement whatever policy for processing you want - process the whole history or only the last state, etc. Hope it helps, I am not sure I got the problem right.
__________________
Daniel @ [www.littletutorials.com]
Language is froth on the surface of thought

Last edited by danielstoner : 04-23-2008 at 11:37 PM.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-23-2008, 11:30 PM
xfrag's Avatar
Member
 
Join Date: Apr 2008
Location: Athens, Greece
Posts: 4
xfrag is on a distinguished road
If I got it right, you want to have a Java GUI to control your C application, right?
But I didn't understood if you start the two processes separately (start the Java process witch waits in server mode and then start the C process with connects to the Java process as a client) or the one starts the other (C process starts the Java process and then connects to it as a client).

If the second case best describes what you're trying to do, then you should consider using JNI. As you're familiar with C, you should not have a problem to follow the instructions described in this book (chapter 7 - "The Invocation Interface" shows how to start the JVM) and get rid of sockets and synchronization issues completely.

I've done exactly the same thing to pass events triggered by a Java process to a native application. If you decide to follow this path I can help you by posting here parts of the code I've already written.
__________________
X-Frag :: |JavaWords|
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
If JNI thread call the java object in another thread, it will crash. skaterxu Advanced Java 0 01-28-2008 08:02 AM
main thread question? frejon26 New To Java 1 01-24-2008 11:13 PM
Creating a Thread (extending Java Thread Class) JavaForums Java Blogs 0 12-19-2007 10:31 AM
main() thread in Java JavaForums Java Blogs 0 12-17-2007 01:21 PM
ERROR: Exception in thread "main" java.lang.NoSuchMethodError: main barney New To Java 1 08-07-2007 08:10 AM


All times are GMT +3. The time now is 12:32 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org