PDA

Click to See Complete Forum and Search --> : DoEvents Equivalent


reeset
Aug 20th, 2001, 01:43 AM
I've been dabbling a a little bit a Java, porting an application that I wrote in VB & C to Linux. However, I'm having a problem. I have one area where I have a loop that is executed a lot. The program is basically a string parser, and the loop is necessary to work through the string. These string come from large files (200 MB and Up), and have a special delimiter. I've created a class to hold my parsing functions, and I'm having no problem getting the desired strings. However, this looping could take as little as 5-10 seconds (for small files) or 10 - 15 minutes. I am looking for a way to free the operating system to perform events (one of those events being a progressbar and status textbox.)

Can someone tell me how Java handles this sort of thing?


--Thanks

Dillinger4
Aug 20th, 2001, 01:59 PM
MultiThreading..........

Dillinger4
Aug 20th, 2001, 02:14 PM
Just remember that multithreading with the JVM on diffrent OS's
works diffrently.

On unix, solaris and i believe Lunix the JVM has been implemented to use a preemtive scheduling approach.
Where the higest priority thread continues to exectue unless it dies, waits, or is preempted by a higher priority thread coming into existence. The latter can occur as a result of a thread lowering it's priority of creating a higher priority thread.

On Windows and Macintosh follow the time slicing approach when a given thread exectues for a specific amount of time and then enters the ready state. At this point in time the thread scheduler determines whether it should return the thread to the ready state
or sechuldule a diffrent thread.

To create a seperate thread of execution you can either subclass
Thread and override it's run() method to provide an entry point into the threads execution, or you can implement a runnable interface and pass that class to a threads constructor.

reeset
Aug 20th, 2001, 03:33 PM
Could you give an example. I have a class that I import into my project. It looks something like this (truncated):


//This is the import list
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import utilities.File.FileHandler;
import New.Generic.MyClass;

//This is the code that initiates the function. This is called from
//the mouse click event on a radiobutton.

public void cmd_BreakMouseClicked(java.awt.event.MouseEvent e)
{
String str_Source;
String str_Dest;
boolean bool_continue=true;

txt_status.setText("Processing Files...Please wait.");
repaint();
str_Source=txt_Source.getText();
str_Dest=txt_Dest.getText();

if (str_Source.length()==0) {
txt_status.setText("Source File cannot be left blank...Stopping");
bool_continue=false;
}

if (str_Dest.length()==0 && bool_continue==true) {
txt_status.setText("Destination file cannot be left blank...Stopping");
bool_continue=false;
}

if (bool_continue==true) {
repaint();
int lng_count=MyClass.ParseFile(str_Source, str_Dest);
txt_status.setText(lng_count + " records have been broken.");
}

cmd_Break.setSelected(false);
}





//This is from the Generic Class file

package New.Generic;
import java.io.*;
import java.lang.*;


public class MyClass {

public static int ParseFile(String str_Source, String str_Dest){
//Truncated
}
}



So how would I thread this? Also, the loop that is causing me such grief is in the ParseFile Method.

Thanks for you help so far

Dillinger4
Aug 20th, 2001, 04:07 PM
First off (and it's just a suggestion) instead
of writing an parse method from scratch
why dont you use the java.util.StringTokenizer
class to parse your file? This was a previous
thread about the StringTokenizer class.


http://64.4.16.250/cgi-bin/linkrd?_lang=EN&lah=259f96e623c1d882fa983ea3be44db6c&lat=998340860&hm___action=http%3a%2f%2fwww%2evbforums%2ecom%2fshowthread%2ephp%3fthreadid%3d97618%26goto%3dnewpost

filburt1
Aug 20th, 2001, 04:11 PM
Originally posted by reeset
So how would I thread this? Also, the loop that is causing me such grief is in the ParseFile Method.

Thanks for you help so far

http://java.sun.com/docs/books/tutorial/essential/threads/

Dillinger4
Aug 20th, 2001, 04:28 PM
Thats what i usually do but i got tired of refering people to Sun's site. :p