Dangerous code up for peer review

Discussion in 'Java' started by steve, Sep 1, 2004.

  1. steve

    steve Guest

    Hi,
    looking for some advice,

    I have a database for addresses coded in java.

    to print the addresses, a jframe is popped up that holds various report
    layouts.
    the user chooses a layout then this launches Jasper reports.

    basically when the user presses the print button is the current screen is
    hidden.
    then a report layout screen is popped up, ( this cannot be a modal, as it
    would sit on top of any screen generated by jreports)

    the problem was , as the report layout screen was not a modal , the code was
    returning directly back to the "mother screen" ,and un-hiding it.


    to get round this problem I have implemented a couple of linked lists, where
    the mother screens sets up a separate thread and then calls the child
    screens to get their status.



    here is a small section of the jasper report compiler
    private void CancelButton_actionPerformed(ActionEvent e) {
    sendStatus(CMD_SIGNAL_GOOD_EXIT); //send exit to calling routine


    this.setVisible(false);
    }
    private void this_windowClosed(WindowEvent e) {
    sendStatus(CMD_SIGNAL_GOOD_EXIT); //send exit to calling routine


    //cancel the import
    //here we need to exit the screen
    this.dispose();
    }

    .......

    here is the signalling routine.

    public void sendStatus(int currentStatus) {
    String aa = String.valueOf(currentStatus);
    addWork(aa);
    }

    public synchronized void addWork(Object o) {
    queue.addLast(o);
    notify();
    }

    //it is possible that the program could get hung here
    //if the normal flow is interrupted
    public synchronized int getWork() throws InterruptedException {
    while (queue.isEmpty()) {
    wait();

    }

    return Integer.parseInt((String) queue.removeFirst());
    }


    to stop the mother screen from being shown i have

    r = new Runnable() {
    public void run() {
    try {

    call the layoutscreen & jasper reports here
    ReportWriter doReport = new ReportWriter(params,
    my_vars.dbconn, errorlogger);
    while (statusFlag != CMD_SIGNAL_GOOD_EXIT) {
    statusFlag = doReport.getWork();
    }
    } catch (Exception ex) {
    Error_stuff.handleError(ex, -1, -1);
    } finally {
    show();
    repaint(); //refresh the screen
    }
    }
    };
    new Thread(r).start();
    } catch (Exception ex) {
    Error_stuff.handleError(ex, -1, -1);
    }

    i'm not really happy with the safety of the code, even though the exceptions
    and all exits from the child screen are covered, and after testing the mother
    screen is always shown again, even after an error.
     
    steve, Sep 1, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John O'Conner
    Replies:
    1
    Views:
    480
    totojepast
    Jan 30, 2004
  2. Sudheer
    Replies:
    2
    Views:
    1,317
    Roedy Green
    Apr 1, 2004
  3. Guy Noir

    Re: peer to peer messaging

    Guy Noir, May 26, 2005, in forum: Java
    Replies:
    7
    Views:
    693
    Owen Jacobson
    May 31, 2005
  4. Matt Gessner
    Replies:
    1
    Views:
    1,397
  5. Replies:
    0
    Views:
    376
Loading...

Share This Page