Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Some clarifications... By reading your code, the only thing I see is that your class WellParameters implements the Interfaces FocusListener and ActionListener (not static classes). As far as I can figure out from your code, the methods <strong>focusGained(FocusEvent e)</strong> and <strong>focusLost(FocusEvent e)</strong> are implemented from the former Interface and updates the values of the static class, and you would depend on same calculated values in the ActionListener event <strong>actionPerformed()</strong>. The problem you are facing here is race-condition regarding the static instance values.</p> <blockquote> <p><a href="http://java.sun.com/docs/books/performance/1st_edition/html/JPAppGC.fm.html" rel="nofollow">http://java.sun.com/docs/books/performance/1st_edition/html/JPAppGC.fm.html</a> A.3.4 Unreachable</p> <p>An object enters an unreachable state when no more strong references to it exist. When an object is unreachable, it is a candidate for collection. Note the wording: Just because an object is a candidate for collection doesn't mean it will be immediately collected. The JVM is free to delay collection until there is an immediate need for the memory being consumed by the object. It's important to note that not just any strong reference will hold an object in memory. These must be references that chain from a garbage collection root. GC roots are a special class of variable that includes</p> <p><li>Temporary variables on the stack (of any thread) <li> <strong>Static variables (from any class)</strong> <li> Special references from JNI native code</p> </blockquote> <p><strong>Based on this Garbage Collection documentation, I suspect that ALL the static references of your class <em>KillWellCalculations</em> were eligible to be garbage collected after the call to the FocusEvent methods and, for this reason, they are not available by the time the event <em>actionPerformed()</em> is fired.</strong></p> <p>You can still use the static methods of the class KillWellCalculations as a utility class only if this class is used by other classes. If not, you can transform it into a Value class that holds the calculations for you, WITHOUT the static references. As you need to have a reference to an instance of a class that holds the values of the calculation... For instance:</p> <pre><code>public Class CalculatedValues { private int measuredDepth; private double mudInActivePits; public static CalculatedValues makeNew() { return new CalculatedValues(); } public void setMeasuredDepth(String measuredDepthTString) { if (measuredDepthTString == null) { throw new IllegalArgumentException("The measured depth must be provided."); } try { this.measuredDepth = Integer.parseInt(measuredDepthTString); } catch(NumberFormatException nfe) { throw new IllegalArgumentException("The value provided is not an interger."); } } public int getMeasuredDepth() { return measuredDepth; } public void setMudInActivePitsT(String mudInActivePitsTString) { if (mudInActivePitsTString == null) { throw new IllegalArgumentException("The measured mudInActivePits must be provided."); } try { this.mudInActivePits = Double.parseDouble(measuredDepthTString); } catch(NumberFormatException nfe) { throw new IllegalArgumentException("The value provided is not an double."); } } public double getMeasuredDepth() { return mudInActivePits; } //... //... // MORE THE OTHER VALUES/PROPERTIES IMPORTANT/NEEDED BY THE CALCULATION. public void doAllCalculations() { // YOU HAVE TO IMPLEMENT THE LOGIC FOR THOSE ONES, OPTIONALLY USING THE SAME UTILITY/HELPER STATIC METHODS FROM setPressureBeforeCasingBurstAndFormationFracture(); setCirculatingPressures(); setTriplexPumpCapacity(); } } </code></pre> <p>Then, modify the constructor of the class to have an instance of the value object:</p> <pre><code>... ... // THE VALUE OBJECT REFERENCE WITH THE VALUES YOU NEED TO HOLD DURING THE FORM INTERACTION private CalculatedValues calculatedValues; WellParameters() { super("Well Parameters", true, true, false, true); this.setBounds(0, 0, 600, 385); this.setVisible(true); this.setLayout(new BorderLayout()); ...//GUI Stuff this.add(submitButtonPanel, BorderLayout.SOUTH); // THE VALUE OBJECT REFERENCE... calculatedValues = CalculatedValues.makeNew(); } </code></pre> <p>Then, update the reference with the calculation:</p> <pre><code>@Override public void focusLost(FocusEvent e) { try { if(e.getSource() == measuredDepthT) { //KillWellCalculations.measuredDepth = Integer.parseInt(measuredDepthT.getText()); // the exceptions thrown can be caught in the catch below and you can display the error message from the value class. calculatedValues.setMeasuredDepth(measuredDepthT.getText()); ...//Others // collect other values as well... } else if(e.getSource() == mudInActivePitsT) { //KillWellCalculations.mudInActivePits = Double.parseDouble(mudInActivePitsT.getText()); // do try/catch for the possible runtime exception and display an error message calculatedValues.setMudInActivePitsT(mudInActivePitsT.getText()); } } catch (Exception ignore) { } } </code></pre> <p>The the updates on the final step also using the instance reference:</p> <pre><code> @Override public void actionPerformed(ActionEvent e) { try { if(e.getSource() == submitButton) { System.out.println(KillWellCalculations.pumpEfficiency); // THE REFERENCES THAT THIS STATIC METHOD USE WERE ALL GARBAGE-COLLECTED AT THE TIME OF THE CALL... IF SHOULD HAVE THE CALCULATED METHODS IN THE VALUE CLASS. SOMETHING LIKE THE FOLLOWING: // KillWellCalculations.setPressureBeforeCasingBurstAndFormationFracture(); //Doesn't work //KillWellCalculations.setCirculatingPressures(); //KillWellCalculations.setTriplexPumpCapacity(); //System.out.println(KillWellCalculations.mudInActivePits); //System.out.println(KillWellCalculations.pumpFactor); //System.out.println(KillWellCalculations.finalCirculatingPressure);} // DO THE FINAL CALCULATION IN A SINGLE METHOD IN THE VALUE OBJECT. calculatedValues.doAllCalculations(); // HERE ARE THE GETTERS FROM THE CALCULATED VALUES OF THE DO ALL CALCULATIONS YOU HAVE TO IMPLEMENT. System.out.println(calculatedValues.getMudInActivePits()); System.out.println(calculatedValues.getPumpFactor()); System.out.println(calculatedValues.getFinalCirculatingPressure());} // CONSIDERING YOU'RE DONE WITH THE VALUES, JUST CLEAR THE INSTANCE VALUES // AS THIS REFERENCE IS NOT STATIC AND IT WILL NOT BE GARBAGE-COLLECTED. calculatedValues.clearValues(); } catch(Exception ignore) {} } </code></pre> <p>I did some work way back related to GUI... You can see a very similar example at <a href="http://code.google.com/p/marcellodesales-cs-research/source/browse/trunk/grad-ste-ufpe-brazil/ptf-add-on-dev/src/br/ufpe/cin/stp/ptfaddon/view/swing/execution/JWizardInternalFrame.java" rel="nofollow">http://code.google.com/p/marcellodesales-cs-research/source/browse/trunk/grad-ste-ufpe-brazil/ptf-add-on-dev/src/br/ufpe/cin/stp/ptfaddon/view/swing/execution/JWizardInternalFrame.java</a></p> <p>Good Luck!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload