Results 1 to 7 of 7

Thread: DoEvents Equivalent

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316

    DoEvents Equivalent

    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

  2. #2

  3. #3
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    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.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    Could you give an example. I have a class that I import into my project. It looks something like this (truncated):

    Code:
    //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);
    }
    Code:
    //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

  5. #5
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    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?_l...goto%3dnewpost

  6. #6
    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/tutor...ntial/threads/

  7. #7

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width