Thread - GUI vs Database

Folks
I have a performance intensive task within my init method (the database part). I would like to seperate this from the loading of the GUI... therefore I am thinking threads.
I am vaguely familar with the two thread options that exist. I dont particularly wish to create a specific class for this. Therefore I am thinking towards implementing Runnable option.
The question is, doing this method I overide the run() method. How do I put the building of the GUI in one thread and the database performance in another...
Thanks for you help.

One clarification question: If I implement the code above,
hence put the database operations in a thread and leave the
init code untouched would I then be effectively running two
threads. OR would I need to specifically put the init()
method AND database operations in TWO seperate threads.Answer: the "main" thread (that you do not explicitly create) will do the init code. The other thread that you do explicitly create, will do the database work. In other words, take your existing init() code, only insert the thread-starting code at the top.
class YourApplet extends Applet
   public void init()
      // before doing anything else, get the worker going
      DatabaseWorkerThread databaseWorkerThread = new DatabaseWorkerThread();
      databaseWorkerThread.start();
      // get the gui ready
      // here the main thread will do all of the gui work as normal
      // (meanwhile, the other thread is working hard on the database stuff, but
      //  we never know what progress it has made at any point; at end of init,
      //  we don't know whether it is done or not -- or even started for that matter)
   } // end of init method
   class DatabaseWorkerThread extends Thread
      public void run()
         // the database work
   } // end of inner class DatabaseWorkerThread
} // end of class YourApplet(My choice to extend thread rather than implementing Runnable makes no difference in the reasonable simple case of this short example.)
/Mel

Similar Messages

  • Running a Java Multi Thread Program in database

    I have created a multi threaded program in Java and it runs successfully from the command prompt. I want to create a DBMS Job which will wake up at regular intervals and runs the java program(Java stored procedure). Is this possible in 9.2/10G ?? If Yes, will there be any impact on the DB performance/increase memory etc.,
    The database (9.2...) resides on a RH 2.3 AS box.
    Any ideas...
    Thanks,
    Purush

    Purush,
    Java stored procedures cannot be multi-threaded. Well, they can, but the threads will not run in parallel. You may be able to find some more information in the Oracle documentation, which is available from:
    http://tahiti.oracle.com
    Good Luck,
    Avi.

  • Multi-Threaded gui components and accessor methods

    hello, I'm working on a small gui component which makes use of swingworker to deal with time consuming methods.
    My question is what is the best way to handle accessor methods for example to tackle the following code scenario:
    MyComponent myComponent = new MyComponent();
    myComponent.render(); // long task handed out to a thread
    myComponent.getVariable(); // will only return correct value if render() has completed
    Is the best option to use a Listener and fire a 'render completed' event?
    Thanks for any ideas,
    bm

    I think that's good approach to go with.
    Sai Pullabhotla.

  • Thread monitoring for database query

    Hi,
    I need to be able to store a database query in a thread. This means that the entire query from executing to return should take place in this thread (as well as connection etc). I would then like to know when it have finished its work so i can carry on some more porcessing.
    I tried doing this with two threads, one to do the work and the other to 'watch' and then tell me when is is done. However, i errors 'every now and again' to which i can attribute to my thread structure not working properly. I am using a synchronised class and code post the code if anyone wishes to see it, however, i would appreciate it if someone could give me a basic structure to how i can go about this so that i do not get these 'random' errors.
    Thanks Rudy

    Okay -
    I have an idea. Withut fully implementing your code, mind you.
    If looks like you're having problems with concurrent access to your Vector.
    A Vector is, of course, a Collection and a List (interfaces) - these are not thread safe. To make them thread safe, you need to "wrap" them.
    <lifted from JavaDocs>
    public static Collection synchronizedCollection(Collection c)
        Returns a synchronized (thread-safe) collection backed by the specified collection. In order to guarantee
    serial access, it is critical that all access to the backing collection is accomplished through the returned
    collection.
        It is imperative that the user manually synchronize on the returned collection when iterating over it:
      Collection c = Collections.synchronizedCollection(myCollection);
      synchronized(c) {
          Iterator i = c.iterator(); // Must be in the synchronized block
          while (i.hasNext())
             foo(i.next());
        Failure to follow this advice may result in non-deterministic behavior.
        The returned collection does not pass the hashCode and equals operations through to the backing
    collection, but relies on Object's equals and hashCode methods. This is necessary to preserve the
    contracts of these operations in the case that the backing collection is a set or a list.
        The returned collection will be serializable if the specified collection is serializable.
        Parameters:
            c - the collection to be "wrapped" in a synchronized collection.
        Returns:
            a synchronized view of the specified collection.</lifted from JavaDocs>
    Give your Vector a wrapper and see if that solves your problem.
    +M                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Canot post thread to Oracle Database 10g Express Edition Forum

    Is it just me or is there an issue with posting a thread to the Oracle Database 10g Express Edition Forum? Every other forum I have tried has worked OK, but the XE forum results in a refresh of the currently displayed page. I am not able to reply to an existing thread either.
    Thanks

    I tested and the post link now works.
    Thanks

  • How to use muti-thread to query database?

    if i want to use two or more threads to query a database for data,what should i do?anybody know?

    Hi,
    I have 2 suggestions to help you do this.
    First, the Berkeley DB XML Transaction Guide uses has a multi-threaded application and several discussions about DB_THREAD.
    For more information see:
    http://www.oracle.com/technology/documentation/berkeley-db/xml/gsg_xml_txn/cxx/introduction.html#multithread-intro
    The following section should also be useful:
    http://www.oracle.com/technology/documentation/berkeley-db/xml/gsg_xml_txn/cxx/txnconcurrency.html#concurrenthandles
    If after reading about this and trying to implement you have a specific question, please post it here.
    You might also take a look in the Berkeley DB examples, TxnGuide.cpp which is a multi-threaded application.
    Ron

  • Thread: stand by database

    hye,
    I have performed standby db scenerio on 10g. early everything was going fine, logs were transferred from prod db to standby db and i run the command to see the available data on standby " alter database open read only" after that
    I run this command to be disconnect from standby session
    sql> alter database recover managed standby database cancel;
    sql>shut immediate;
    sql> startup mount;
    sql>alter database recover managed standby database disconnect from session;
    after that my standby do not able to accept logs.
    how could i resolve this?
    thanks

    hi ,
    my alert files showing:
    Using STANDBY_ARCHIVE_DEST parameter default value as /PGHProdDB/archive/paceview/
    Redo Shipping Client Connected as PUBLIC
    -- Connected User is Valid
    RFS[1]: Assigned to RFS process 29997
    RFS[1]: Identified database type as 'physical standby'
    Tue Aug 7 17:35:10 2012
    RFS LogMiner: Client disabled from further notification
    Tue Aug 7 17:35:20 2012
    alter database recover managed standby database disconnect
    Tue Aug 7 17:35:20 2012
    Attempt to start background Managed Standby Recovery process (paceview)
    MRP0 started with pid=16, OS id=30002
    Tue Aug 7 17:35:20 2012
    MRP0: Background Managed Standby Recovery process started (paceview)
    Managed Standby Recovery not using Real Time Apply
    parallel recovery started with 3 processes
    Tue Aug 7 17:35:25 2012
    Waiting for all non-current ORLs to be archived...
    Tue Aug 7 17:35:25 2012
    Errors in file /opt/oracle/102/rdbms/log/paceview_mrp0_30002.trc:
    ORA-00313: open failed for members of log group 1 of thread 1
    ORA-00312: online log 1 thread 1: '/PGHProdDB/archive/paceview/redo1.log'
    ORA-27037: unable to obtain file status
    Linux-x86_64 Error: 2: No such file or directory
    Additional information: 3
    Tue Aug 7 17:35:25 2012
    Errors in file /opt/oracle/102/rdbms/log/paceview_mrp0_30002.trc:
    ORA-00313: open failed for members of log group 1 of thread 1
    ORA-00312: online log 1 thread 1: '/PGHProdDB/archive/paceview/redo1.log'
    ORA-27037: unable to obtain file status
    Linux-x86_64 Error: 2: No such file or directory
    Additional information: 3
    Clearing online redo logfile 1 /PGHProdDB/archive/paceview/redo1.log
    Clearing online log 1 of thread 1 sequence number 154
    Tue Aug 7 17:35:25 2012
    Errors in file /opt/oracle/102/rdbms/log/paceview_mrp0_30002.trc:
    ORA-00313: open failed for members of log group 1 of thread 1
    ORA-00312: online log 1 thread 1: '/PGHProdDB/archive/paceview/redo1.log'
    ORA-27037: unable to obtain file status
    Linux-x86_64 Error: 2: No such file or directory
    Additional information: 3

  • Linking my gui and database

    my mysql server is up and running and my connection code is correct because am not getting any error. so how shuold i link the two search that i enter info from the GUI i have created and its saved to my database. i,d really appreciate help from anyone.

    what kind of gui? swing or web?
    %

  • Thread Gui Socket Challange

    The problem is when i start the thread form the MAIN class, the connection is ok but when i try to update the GUI the update does not come true.
    The System does not update the component i like to add tru the following methode.
    Why does the system not update and how can i make it work.
    computerview.setComputer("Izzy",new ComputerControl());
    import javax.swing.*;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.net.ServerSocket;
    import java.net.Socket;
    import java.awt.event.ActionEvent;
    public class Server extends Thread{
            JButton addComp = new JButton();
            String inputLine;
            ComputerView computerview = new ComputerView();
        public void startServer() throws IOException {
            ServerSocket serverSocket = null;
            try {
                serverSocket = new ServerSocket(4444);
            } catch (IOException e) {
                System.err.println("Could not listen on port: 4444.");
            Socket clientSocket = null;
            try {
                clientSocket = serverSocket.accept();
            } catch (IOException e) {
                System.err.println("Accept failed.");
            PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
            BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
            out.println("Hello Client");
            while ((inputLine = in.readLine()) != null) {
                 String state = "WAITING";
                System.out.println(state);
                if(state.equals("WAITING")){
                    if (inputLine.equals("ID")){
                       System.out.println("Client :"+inputLine );
                          out.println("Who are you?");
                          state = "WAITINGFORID";
                          System.out.println(state);
                if(state.equals("WAITINGFORID")){
                          computerview.setComputer("Izzy",new ComputerControl());
                          out.println("You are now Registred!");
                          state = "WAITING";
                          System.out.println(state);
        public void run(){
             try {
                startServer();
            } catch (IOException e) {
                System.err.println(e);
    }

    As a general rule all GUI components should be updated from the event thread thread which means you may need to use the SwingUtilities.invokeLater(...) method to do the updates. This thread give a simple example:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=437592

  • Need help with Threading GUI progress bar

    Anyone able to help? I'm sure you've seen this a million times. I've google'd around and tried examples but still can't get a progress bar to work properly under the following situation:
    1. Created a panel with several components to select directory, display directory in tree etc.
    2. When a specific button (Search) is clicked, I want a secondary window to popup and report progress of searching down the directory.
    As you'll probably guess, the progress window isn't being updated until the end. I'm using Threads and using InvokeLater but nothing happens. Is there any good example that does the above? I can't seem to find one to figure this out.
    Thanks
    Speedy.
    Sample code:
    main.java:
    ========
    public class Main {
    public static void main(String[] args) {
    MainPanel mainPanel = new MainPanel();
    mainPanel.show();
    MainPanel.java:
    ============
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    public class MainPanel extends JFrame implements ActionListener {
    public MainPanel() {
    this.setSize(100,100);
    JButton startButton = new JButton("Start");
    this.getContentPane().add(startButton);
    startButton.addActionListener(this);
    public void actionPerformed(ActionEvent event) {
    ProgressPanel pp = new ProgressPanel();
    pp.show();
    SimpleTask st = new SimpleTask(pp);
    st.start();
    while (st.isAlive()) {
    System.err.println("waiting..");
    try {
    Thread.sleep(100);
    } catch (Exception e) {};
    System.err.println("finished!");
    SimpleTask.java:
    =============
    import javax.swing.SwingUtilities;
    public class SimpleTask extends Thread {
    ProgressPanel pp = null;
    public SimpleTask(ProgressPanel _pp) {
    pp = _pp;
    this.setDaemon(true);
    int i = 0;
    String position = "";
    public void run() {
    Runnable updateGUI = new Runnable() {
    public void run() {
    pp.setText(position);
    try {
    for (i=0; i<50; i++) {
    position = "Now on = " + new Integer(i).toString();
    System.err.println(position);
    SwingUtilities.invokeLater(updateGUI);
    sleep(100);
    } catch (Exception e) {}
    ProgressPanel.java:
    ===============
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    public class ProgressPanel extends JFrame {
    private JLabel label = new JLabel();
    public ProgressPanel() {
    this.setSize(200,200);
    this.setLocation(100,100);
    this.getContentPane().add(label);
    setText("Start");
    public void setText(String text) {
    label.setText(text);
    }

    Ok, I'll look down that road. I should have said the Thread is being used because the current while loop will be changed to perform real work. Just an example at the moment to show what I'm trying to do. Does this make a difference? The real task will be to drill down directories, counting file types/dirs etc...

  • Getting connection toa database in a thread

    Hi
    I need guidance on how to get connection to a database inside a thread.Let me explain in detail.
    I am developing a chat application. As normal my chat server assigns each user an instance of a chathandler class which runs as a thread.The problem is that i need to connect to database inside this thread to implement some group wise logic in the broadcast method of chathandler thread.
    Now for this can i create a connection object each time in the thread or can i use a common connection object ? If i go for the second method will it cause any concurrency issue ?
    Thanks in advance

    Hi
    I need guidance on how to get connection to a
    database inside a thread.What other way is there? You always get access to a database inside a thread.
    Let me explain in detail.
    I am developing a chat application. As normal my
    chat server assigns each user an instance of a
    chathandler class which runs as a thread.The
    problem is that i need to connect to database inside
    this thread to implement some group wise logic in
    the broadcast method of chathandler thread. No, database connections are for persistence. Group wise logic belongs somewhere else.
    Now for this can i create a connection object each
    time in the thread Yes, for each database access. Create it, use it, close it. Use a connection pool to amortize the cost of opening a connection.
    or can i use a common connection object ? If you're foolish you can. How scalable is an app with one connection?
    If i go for the second method will it cause
    any concurrency issue ?You'll have isolation and concurrency issues to worry about in any case.
    %

  • Can you force a Oracle Update Statement to use a specific database thread?

    We are attempting to write a Oracle Update Statement to update a value on all records in a single column. We are updating a column with a value found in a history table. Simple enough. We do it all the time. It works but we are having contention issue with users on the system using the main database threads and updating the same table at the same time. So what is happening is the update uses up all the available database threads and then the users just get timeouts and can't update. What we are trying to determine is can I write it to force the update statement to use a specific thread on the database when it is running?
    Here is the current update statement
    UPDATE
    TASK_DATA TSK
    SET
    dttSTATUS_WORK_IN_PROGRESS_TIM =
    SELECT
    HIS.T5
    FROM
    H2839 HIS
    WHERE
    TSK.REQUEST_ID = HIS.ENTRYID
    AND
    HIS.T5 IS NOT NULL
    AND
    TSK.dttSTATUS_WORK_IN_PROGRESS_TIM IS NULL
    Edited by: user11307503 on Oct 21, 2009 3:47 PM

    the update uses up all the available database threads and then the users just get timeouts and can't updateI'm not convinced that you're got a clear picture of how Oracle works and what is going on here.
    You're updating TASK_DATA, the whole table.
    Writers don't block readers - that's a key principle of Oracle.
    But if all the other users are trying to update a row or rows in TASK_DATA at the same time as your other process is updating all rows in the table, then there's going to be contention.
    This is not about "using up all available database threads" - that's nonsense.
    This is (probably) about sessions trying to update rows that your other process has locked.
    1. Get a clear picture of what the sessions are waiting on - it's probably TX locks.
    2. How many rows are you updating with this update on TASK_DATA?
    3. How long does it take? How often do you do it? Is there no quieter time when you can do it?

  • JDBC Sender Adapter Threads and DB connections

    Hello,
    I have got a few questions regarding the behaviour of the JDBC sender adapter.
    Suppose I have configured a short polling intervall of 10 seconds. On the first poll a message is processed. How does the JDBC sender adapter behave when there is a second poll after 10 seconds and data is available? Does it wait until the first poll has been processed completely or does it start a second thread processing a second message in parallel? If the latter is true, would a second database connection be retrieved or would both threads share one database connection? What would happen if a large number of unprocessed threads were waiting?
    Kind regards,
    Heiko

    hi heiko,
    whether the first thread is successful or not automatically a new thread is created after the polling interval.if the previous thread is accessing a data the database would lock that one for theat thread so until the lock is released the other thread has to wait for it.so you can see the thread waiting in SAP WEb GUI.There you can see a green indicator on the status column corresponding to the service.
    so a new service is created after the pollling interval irrespective of the pevious service's result and it waits in the queue till its resource is otained.
    configuring sender jdbc to poll a databe is not an advisable one that too this short polling interval.this will increase the queue length and obviously cause performance issues...........

  • Can multiple threads share the same cursor in berkeley db java edition?

    We use berkeley db to store our path computation results. We now have two threads which need to retrieve records from database. Specifically, the first thread accesses the database from the very beginning and read a certain number of records. Then, the second thread needs to access the database and read the rest records starting from the position where the cursor stops in the first thread. But, now, I cannot let these two threads share the same cursor. So, I have to open the database separately in two threads and use individual cursor for each thread. This means I have to in the second thread let the cursor skip the first certain number of records and then read the rest records. However, in this way, it is a waste of time letting the second thread skip a certain of records. It will be ideal for us that the second thread can start reading the record just from the place where the first thread stops. Actually, I have tried using transactional cursor and wanted to let the two threads share the same transactional cursor. But it seems that this didn't work.
    Can anyone give any suggestion? Thank you so much!
    sgao

    If your question is really about using the BDB Java Edition product please post to the JE forum:
    Berkeley DB Java Edition
    If your question is about using the Java API of the BDB (C-based) product, then this is the correct forum.
    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • DATABASE STRUCTURE HAS BEEN MODIFIED PROBLEM...

    Hi
    I am getting the message " The database structure has been modified " after every 5 minutes.
    Regards

    Hi,
    You may check this thread:
    Message: "The database structure has been modified" every time I log to SAP
    Thanks,
    Gordon

Maybe you are looking for

  • Slideshow software-which best to use?

    I will admit I posted this first on Final Cut Express as I wasn't sure where to post my question.  But, as I found other posts, many similar, but much older, posts (ie software options probably much different now) were posted on iDVD's forum... And,

  • Getting my iTunes on my G5 to recognize my iPod

    Help!!!!!!!!! I made the mistake of hooking up my iPod to a wintel machine when I first bought it. Now, when I hook the iPod up to my G5, it doesn't seem to know that it's there. So the question is, how do I get iTunes on my Mac to recognize my iPod

  • Customer as business partner

    Hi Gurus,                      I want to create my cusotmer which is currently having partner functions as Sold to party,ship to party, bill to party and payer. when I goto BP transcation in ECC and try selecting all for roles, I do not get any one o

  • Purchasing Release strategy in Shipment Cost

    Hy collegues, i need some information about Purchasing Release strategy in shipment cost. 1° question: Release strategy on Service entry sheet document Is it possible set the Release strategy on Service entry sheet document? I have just created a rel

  • Creating Max Querry

    I am looking to create query to find a Maximum value in a column called "total_full_energy_b" between the dates of X and Y.  The dates are all sent and live in column "cdate".  Any help would be greatly appreciated. My SQL programmer is on vacation a