Dangerous code up for peer review

S

steve

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top