suvelee sarpotdar

Greenhorn
+ Follow
since Apr 20, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by suvelee sarpotdar

Thanks for the reply. I implemented thread pool from scratch. I have given some system.out statements which are printed from the task. No statements are printed from the last task. Also at the end of the program, I am expecting 40,000 records in my table. However only 35,000 records are written into the table since the last task is not executed.

Code snippet from thread pool that assigns task and creates thread if no idle threads are found or waits for one of the threads to finish


Code snippet that waits for all tasks to finish executing


Code snippet from the worker thread which executes the runnable task.
Hi All,

I am not sure if this problem has been addressed in any of the previous posts. I have implemented a thread pool manager which creates 5 threads and assigns task to these threads. The thread pool manager waits for all threads to finish and also for all tasks to finish before exiting. The task given to the threads consists of connecting to Oracle database and executing a SQL proc to update records in a table.

If I execute the jar file for this application on a windows based machine, I get the results as expected. However if I run the same jar file on linux platform, the last task is not executed by any of the threads. The behavior of the application is random on linux machine. Sometimes it gives results as expected sometimes it doesn't. Both windows and linux machines have the same JRE installed (1.5).

I am not sure how to debug this issue. Any kind of pointers are most welcomed. Thanks in advance.
Hello Michael,

Thanks a lot. It works perfectly when i remove those lines. Also i have one more question, is it good to handle the events related to the dialog within that dialog class itself or should the events be handled by inner class in the parent frame?

Suvelee
14 years ago
Hello,

I am pretty new to Java and also to JavaRanch forum. I tried searching through the forum for my problem but couldn't find any solution. I have a parent frame with a button "+" along with some other buttons. Upon clicking this button, a JDialog is opened which takes some input from the user. Dialog has a cancel button along with the usual "X" button on the top. JDialog implements actionlistener which closes( dispose()) the JDialog on clicking cancel or "X" button. I also have a private inner class in the parent frame class which implements all the events for the parent frame.

My problem is that the JDialog closes on clicking the "X" or cancel button twice, i.e. the JDialog is not closed on the 1st click. Following is the code for both parent and the dialog:

//Parent Frame code
//------------------------------------------------------------------------
package ui;

import javax.swing.*;



import java.awt.*;
import java.awt.event.*;


public class CalendarGUI extends JFrame{
/**
*
*/
private static final long serialVersionUID = 1L;
private static GraphicsConfiguration defaultGC = null;
private static String defaultTitle = "Untitled";
private static CalendarGUI cg;

public CalendarImage calImg;
public MonthView cal;
public CalendarToDo calToDo;

public NewEventForm newEvent;
private AllEventHandler ae;
/**
* @throws HeadlessException
*/
public CalendarGUI() throws HeadlessException {
this(defaultTitle, defaultGC);
}

/**
* @param gc Graphics configuration
*/
public CalendarGUI(GraphicsConfiguration gc) {
this(defaultTitle, gc);
}

/**
* @param title Window title
* @throws HeadlessException
*/
public CalendarGUI(String title) throws HeadlessException {
this(title, defaultGC);
}

/**
* @param title Window title
* @param gc Graphics configuration
*/
public CalendarGUI(String title, GraphicsConfiguration gc) {
super(title, gc);
initComponents();

}

public void initComponents(){
this.setLayout(new GridLayout(2,2));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ae = new AllEventHandler();
calImg = new CalendarImage();
cal = new MonthView();
cal.addActionListener(ae);
calToDo = new CalendarToDo();
this.getContentPane().add(calImg);
this.getContentPane().add(cal);
this.getContentPane().add(new JPanel());
this.getContentPane().add(calToDo);
this.setResizable(false);
this.pack();
this.setVisible(true);
}

public static void main(String[] agrs){
cg = new CalendarGUI("Calendar");

}

private class AllEventHandler implements ActionListener {

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Object o = e.getSource();
if(o == cal.jbAddToDo){
newEvent = new NewEventForm(cg);
newEvent.requestFocus();
newEvent.setVisible(true);

}

}

}
}
//------------------------------------------------------------------------
//JDialog Code
package ui;
import business.Event;
import javax.swing.*;

import java.awt.*;
import java.awt.event.*;

public class NewEventForm extends JDialog implements ActionListener{
private JLabel jlAddEvent;
private JLabel jlTitle;
private JLabel jlLocation;

private static GraphicsConfiguration defaultGC = null;
private static String defaultTitle = "Untitled";



public JTextField jtTitle;
public JTextField jtLocation;

public JButton jbCancel,jbDone;

/**
* @throws HeadlessException
*/
public NewEventForm(JFrame parent) throws HeadlessException {
super(parent,"New Event",true);
initComponents();
}

public void initComponents(){
if(getLayout() == null){
setLayout(new GridLayout(8,3,3,3));
}
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
Window owner = this.getOwner();
//this.setResizable(false);
Dimension d1 = this.getSize();
Dimension d2 = owner.getSize();
int x = Math.max((d2.width-d1.width)/2, 0);
int y = Math.max((d2.height-d1.height)/2, 0);
this.setBounds(x,y,d1.width,d1.height);
//this.setSize(200,200);
this.setModal(true);

JPanel form = new JPanel(new GridLayout(8,3,3,3));
jbCancel = new JButton("Cancel");
jbCancel.addActionListener(this);
form.add(jbCancel);
jlAddEvent = new JLabel("Add Event");
jlAddEvent.setHorizontalAlignment(JLabel.CENTER);
form.add(jlAddEvent);
jbDone = new JButton("Done");
jbDone.addActionListener(this);
form.add(jbDone);

jlTitle = new JLabel ("Title: ");
form.add(jlTitle);
jtTitle = new JTextField();
form.add(jtTitle);


jlLocation = new JLabel ("Location: ");
form.add(jlLocation);
jtLocation = new JTextField();
form.add(jtLocation);

this.getContentPane().add(form);
this.pack();
this.setVisible(true);


}


public void actionPerformed(ActionEvent ae){
Object o = (Object)ae.getSource();
if(o == jbCancel){
this.dispose();
} else if (o == jbDone){

Event e = new Event();

}
}

}


Is this happening because I have two actionlisteners? Should the inner class of parent frame handle the events of JDialog too?

Thanks a lot,
Suvelee
14 years ago