home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

how can I find out what processes are running as a result of the current one in java?

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2321
Discussions: 200,942, Posts: 2,379,291, Members: 246,305
Old January 6th, 2003, 11:37 PM   Digg it!   #1 (permalink)
Senior Member
 
Join Date: Oct 2001
Posts: 881
Send a message via AIM to zskillz
how can I find out what processes are running as a result of the current one in java?

here's the deal... I wrote a little program that opens one large file and then creates many little files out of it... it does not necessarily finish making those smaller files in the order that it started making them. (some may take longer then others to process).

I want to create a GUI for it that is temporarily disabled while those processes are still running so that the user doesn't try and run it again accidentally.

now I have never done something like this before, and i'm not really sure if the way that I'm thinking of is really the best or easiest way (so if not, then by all means, make some suggestions ) but here's what my plan is.

I want the user to start the process by pressing a button
i want the program to disable the use of that button until the process is finished.

I was thinking that the best way to do that was to check what "threads" (may be the wrong word) had spawned from the original thread (perhaps by checking the stack or something) and making sure that those completed before the GUI was allowed to return to it's usable state.

does this sound like the right way to go about doing this sort of thing? or am I looking at it all wrong. I'm sure it's a common issue, but I don't really know what to do!

thanks in advance,
-Z
zskillz is offline   Reply With Quote
Old January 7th, 2003, 06:52 PM     #2 (permalink)
Banned
 
qball's Avatar
 
Join Date: Oct 2001
Posts: 447
If what you want is:
Quote:
I want the user to start the process by pressing a button
i want the program to disable the use of that button until the process is finished.

Which is pretty common behavior, is actually accomplished fairly easily.

In GUI terms, the button has a clicked event. This is how you know the button was clicked. This event will contain the code to do what you want the button to do. The button also has an enabled/disabled property. Enabled means you can click the button, disabled means you can't.

So simply, the event code for clicked will look like this:

Code:
//user no clickey
this.enabled = false;
//...
your code
//...
//user can clickey
this.enabled = true;
That's the GUI way. As this is the nature of buttons.

So, no matter what GUI you use, java, VB, PB, Javascript, whatever..., it is basically going to work this way.

With java, there basically exist 2 GUI frameworks. AWT Abstract window toolkit, and Swing. Either way, you'll get the buttons to behave as desired, by just doing the above.
qball is offline   Reply With Quote
Old January 7th, 2003, 08:23 PM     #3 (permalink)
Ultimate Member
 
strangerstill's Avatar
 
Join Date: Oct 2001
Posts: 1,542
Hmm... how are you planning to spawn the child threads?

I tend to use SwingWorker: http://java.sun.com/docs/books/tutor...ml#SwingWorker
in your case, what I would do is something like their IconDemoApplet:
Code:
private void processFile(final String filePath, final int index) {
    final SwingWorker worker = new SwingWorker() {

        public Object construct() {
            // do stuff;
            return; //return value not used by this program
        }

        //Runs on the event-dispatching thread.
        public void finished() {
            markFileDone(index);
        }
    };
    worker.start();  //required for SwingWorker 3
}
markFileDone would then be a method elsewhere in the enclosing class which would set a boolean in an array, and when the whole array is set to true i.e. all files have been processed, it will re-enable the button.
strangerstill is offline   Reply With Quote
Old January 7th, 2003, 09:28 PM     #4 (permalink)
Senior Member
 
Join Date: Oct 2001
Posts: 881
Send a message via AIM to zskillz
yes... that class is exactly what I'm looking for strangerstill....

however, i then have a question about the whole array thing. I'm not sure why I would bother doing all that if I could just do something like check the stack and see if any threads that were spawned off of the primary thread are still running.

wouldn't that be an easier way to do it?

-Z
zskillz is offline   Reply With Quote
Old January 7th, 2003, 11:54 PM     #5 (permalink)
Senior Member
 
Join Date: Oct 2001
Posts: 881
Send a message via AIM to zskillz
wellwellwell... i have an update...

apparently whatever i am doing, it is not threading.... I just wasn't testing it on a big enough information set.

so... here's the update.... my problem seems to have solved itself... the GUI just sort of freezes until the process is finished anyway!

wierd. now I'm positive that I don't understand threads.

-Z
zskillz is offline   Reply With Quote
Old January 8th, 2003, 06:30 AM     #6 (permalink)
Ultimate Member
 
strangerstill's Avatar
 
Join Date: Oct 2001
Posts: 1,542
hmm, I'm not sure I do either.
looking at the API again, it seems what you'd want to do is to create a ThreadGroup and then create a bunch of Threads bound to that ThreadGroup, then you can use ThreadGroup.activeCount() to find how many threads are still running.

The way it seems to me, in Java you do need to explicitly tell the VM to generate threads otherwise all you have is the event-dispatching thread, if you run long operations in that you will lock up your GUI till it returns.

now it might be what you want in this case to have the GUI suspended till the method returns but that's not very nice on the end user, for instance the window will be unable to redraw and you won't be able to provide any feedback on how the operation is going, or even provide a 'cancel' interface - remember that time spent not knowing what's going on or how to do anything about it feels five times as long as time spent watching a progress bar! truth!
strangerstill is offline   Reply With Quote
Old January 8th, 2003, 12:12 PM     #7 (permalink)
Senior Member
 
Join Date: Oct 2001
Posts: 881
Send a message via AIM to zskillz
hha! funny that you mention it though, but I have spent some of this morning trying to implement a progress bar for the process!

I am however interested in the threadgroup stuff!!! that is some interesting reading and I'll see what I can get from it.

-Z
zskillz is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (2918)
Hackers global warming emails (5)
windows 7 problem (7)
Wireless Televisions. (10)
CPU fan stops spinning randomly (8)
Regular Build (6)
Is the PSU I received dead? (11)
HIS HD5770 graphic card question (15)
windows vista security holes (9)
Install XP pro and a Vista laptop ?.. (11)
Print spooler problem (13)
Foreign voltage (10)
Dept. of HS: NSA 'Helped' Develop V.. (15)
A good PSU? (10)
Recent Discussions
Wireless Televisions. (10)
Asus P4G8X Mobo (5)
screen resolution vs monitor size (2)
radeon x850xt platinum & shader 3 (4)
sms storage to PC (0)
Regular Build (6)
Open With ..... Win7 (0)
java code for fibonacci (1)
[F@H SPAM 11/16/09] ! 1/2 months to r.. (35)
windows 7 problem (7)
CPU fan stops spinning randomly (8)
Partition Magic caused HDD problem (3)
Is the PSU I received dead? (11)
Have you switched yet? (85)
Point and Shoot Camera Suggestions. (2)
Modern Warfare 2 freeze (13)
wireless user (1)
World's largest Monopoly Game using G.. (332)
Ideal cheap graph card for PC-Gaming? (17)
BIOS won't read disk when I try to fl.. (0)
Install XP pro and a Vista laptop ?? (11)
Graphics Card Upgrade Question (1)
favorit (1)
solutions for virtical white lines on.. (1)
Fire in DVD (2)


All times are GMT -4. The time now is 03:53 PM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28