Threads Stuck On Closing Brace Of While Loop
Apr 14, 2014
While analyzing the thread dumps for a performance issue in our java ee web application, I see many thread dumps stuck on a closing brace of a while loop. Here is the code block of a third party library bitronix (version 1.3.3 SNAPSHOT)
public XAResourceHolderState findXAResourceHolderState(XAResource xaResource) throws BitronixSystemException {
Iterator it = resources.iterator();
while (it.hasNext()) {
XAResourceHolderState xaResourceHolderState = (XAResourceHolderState) it.next();
if (xaResourceHolderState.getXAResource() == xaResource)
return xaResourceHolderState;
}
return null;
}
The thread dumps indicate that many threads are stuck in RUNNABLE state on line number 07. What could be the possible reasons on why a thread could get stuck on a closing brace of a while loop? The iterator of the while loop is a custom implementation.
View Replies
ADVERTISEMENT
Feb 7, 2014
I'm going through a file (MySQL dump) and I wish to take the SQL and create individual files for each table (as opposed to what I do now, which is just run through the whole thing).
<code>
BufferedReader myDumpfileReader = new BufferedReader(new FileReader(tfDumpfile.getText())); BufferedWriter myDumpfileWriter = new BufferedWriter(new FileWriter("/users/linehanp/mydb/bin/tgac_dump/Vanilla.sql"));
while((dumpFileLine = myDumpfileReader.readLine()) != null){ DoStuff();
MyDumfileWriter.write("Whatever");
}
myDumpfileReader.close();myDumpfileWriter.close();
</code>
Now, this all works fine - but what I want to do is create a separate .sql file for each table.
However, I can't figure out the best way to do this - how do I create a new FileWriter (or instance of whatever class is required) as I'm going through the while loop? That or pointing the same one to different files as I go through the loop.
It can be assumed that the file may exceed RAM - I want to do it line by line rather than slurping the entire file as a string and "cheating" that way.
There appear to be many (a bewildering amount of) I/O options and I'm just unsure.
View Replies
View Related
Mar 16, 2014
I'm trying to do the following and my code is putting me in a loop and not allowing me to input a valid entry after using an invalid #.I ask the user for input which contains a loop if the user doesnt use the correct information, however the loop doesnt allow the user to input if the entry fails the which statement
import javax.swing.JOptionPane; // Needed for JOptionPane class
public class LoanQualifier
{
public static void main(String[] args)
{
double salary; // Annual salary
double yearsOnJob; // Years at current job
String input; // To hold string input
// Get the user's annual salary.
input = JOptionPane.showInputDialog("Enter your " +
[code]....
View Replies
View Related
Oct 6, 2014
I have this code running correctly in Eclipse all except that it seems no matter where I declare, highest, lowest, average they always seem to stay at "0". I have a feeling the location of the Initialization is not the error since I have tried moving it to inside differ loops.
Stipulations on writing this code are:
Note: You do not need to use array to save each input score for this lab. A Single loop to read in each grade, compare with the current highest grade, lowest grade, and calculate the running sum at the same time.
import java.util.Scanner;
/*Write a program that prompts the user to enter the total number of students first.
*Then ask the user to input each student’s grade and use loop statements to read in each grade.
*Check input grade to make sure 0<=grade<=100, if the user input any other number, print out warning message and ask the user to input a new grade. Display the highest score, the lowest score and the average.
*/
public class LoopStatements {
// Main Method
public static void main(String[] args) {
// Initialize
int grade = 0; // grade value
[Code] ....
View Replies
View Related
Mar 14, 2014
The problem i believe is that I have the max value set to the first value given out, but every time the loop repeats the Max value gets reset to the next value in the file.
Essentially the program is supposed to read a list of credit card transactions and tell the user which transaction is the highest.
Here's the list of the sample file, note that the number of transactions could change that's why i haven't tried simply passing the values to method.
Bicycle 562.90
Groceries 138.43
Hotel 612.00
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class CreditCards {
public static void main(String[] args) throws IOException {
String fileName = "C:/Users/David/Desktop/CreditCard.txt";
File inputFile = new File(fileName);
[Code] ....
View Replies
View Related
Nov 13, 2014
My issue is that when I run my search, it does find a goal. However, when I try and print the route using my print route method, it just gets stuck in a loop of printing the same two nodes. What is wrong with My A* implementation?
package search;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
[code]....
View Replies
View Related
Feb 14, 2014
I saw code like this.
Set<String> set = new HashSet<String>(){{ add("Hello"); }};
I can understand that it is a HashSet with one element "Hello" in it. I don't understand this syntax. Why there are double curly braces?
View Replies
View Related
May 20, 2014
I have a WindowClosing(WindowEvent e) method, but when I close my window it isn't doing anything inside the method. I am making a launcher and I want to make it so when the actual game window is closed it makes the launcher window visible again.
Java Code: public void windowClosing(WindowEvent e) {
this.jf.setVisible(true);
} mh_sh_highlight_all('java');
View Replies
View Related
Mar 3, 2014
I wrote a program to transfer a file using tcp connection, where I closed socket since the receiver need to detect the end-of--file. But now I like to extend it to multiple file for which i should not close the socket until all the files are send. I can't find a way for this. So how to resolve it.
View Replies
View Related
Jan 23, 2014
I recently made a game. But, I want to package it and give it to my friends. I know that I can create a jar of it and add the images to the folder, but what I would absolutely love is for it to just be a picture with the game name and click to run. The second thing is to replace that java icon to an icon of my preference, which I have been told numerous times to do with
frame.setIconImage(Image image)
which does not work for me.
View Replies
View Related
Feb 21, 2014
Following code I use to run or Launch another application
try {
Runtime.getRuntime().exec("rundll32 url.dll, FileProtocolHandler " + "Path of Application's EXE File");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e, null, JOptionPane.ERROR_MESSAGE);
}
if the above code is to launch another application using java then how can I close/exit the same(another) application using java code once I press the exit button of my java app.
View Replies
View Related
Apr 11, 2015
I show a JDialog window and this window has 3 buttons when I press one of them it should close the window, how do I do that?
View Replies
View Related
May 27, 2015
I am modifying existing code to display graph after pressing calculate button. The graph pop ups in new controller/window. The pop up disappears after closing the application entirely. However I have trouble figuring out if it is possible to close that old/previous pop up and new pop up appears when calculate button is pressed again. Or at least reuse the pop up to display a new graph.
public class AdamCalculationApp extends AbstractCalculation {
/**
* Does a calculation.
*/
public void calculate() { // Does a calculation
control.println("Adam Calculation button pressed.");
double k = control.getDouble("k value"); // String must match argument of setValue
control.println("k*k = "+(k*k));
control.println("random = "+Math.random());
[Code]...
View Replies
View Related
Apr 14, 2015
I have a Dialog with no buttons (the dialog pane contains some graphic elements which act as my buttons). I show the dialog and try to click the close window button on the dialogs title bar, and the dialog does not close! I read the docs and it appears that only dialogs that have one or more buttons can be abnormally closed (and only under certain well defined sensible conditions). How can I abnormally close a dialog with no buttons?
View Replies
View Related
May 18, 2014
I'm doing a project in netbeans. I have to make a on-line bank with all the GUI. In the middle i got stuck with the classcastexception..
public class Banca {
public static void main(String[] args) throws IOException, ClassNotFoundException {
// dati dei clienti
Anagrafica c = new Anagrafica();
[code]...
And here's the class of the activities of an account.. I'm not posting my classes Conto( Bankaccount) & Movimento (Activity) because those two already do what they should..
View Replies
View Related
Mar 19, 2014
How to use a constructor with parameters where the user inputs the information? I'm doing a problem where I create a Delivery class that accepts arguments for the year, delivery number within the year, distance code (1 for short distance, 2 for long), and weight of package. The constructor is supposed to also determine the eight digit delivery number (combining the year and delivery number, like 20140054 for this year, package #54).
I know I'm not close to being done but I'm struck on the application with the constructor parameters. If I'm asking the user to input the information, does that mean I have to create a no argument constructor so it will compile? Right now it won't compile because it's asking for the parameters but I can't put them.
This is the class:
public class Delivery {
int year;
int delNum;
double weight;
int code;
[Code] .....
And the error is:
CreateDelivery.java:22: error: constructor Delivery in class Delivery cannot be applied to given types;
Delivery firstDelivery = new Delivery();
^
required: int,int,int,double
found: no arguments
reason: actual and formal argument lists differ in length
1 error
View Replies
View Related
Sep 26, 2014
I'm writing a temperature converter for class, and I'm done but one piece that I can't wrap my head around.My input scale radiobuttons work fine, but the output scale radiobuttons don't deselect automatically. They're two different button groups and I wrote them identical save for the variable names.
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
[code]....
View Replies
View Related
Apr 13, 2014
I am having trouble grasping 2 dimensional arrays .I have a certain problem:
String[][] words = {
{"Red", "Blue", "Green"},
{"Orange", "Purple". "Yellow"}
[code]....
I ran the code and got OrangePurpleYellowRedBlueGreen.
View Replies
View Related
Jan 23, 2015
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JTextField;
[code]....
Total IS those numbers. But question[10] will not cooperate with me and it's getting a bit aggravating as I can't find a logical reason for it to be doing that.how to perhaps lock the value of total and sTotal after 10 button clicks from any?
View Replies
View Related
Jul 1, 2014
Write a method called isSorted that accepts an array of real numbers as a parameter and returns true if the list is in sorted (nondecreasing) order and false otherwise. For example, if arrays named list1 and list2 store {16.1, 12.3,22.2, 14.4} and {1.5, 4.3, 7.0, 19.5, 25.1, 46.2} respectively, the calls is Sorted(list1) and isSorted(list2)should return false and true respectively. Assume the array has at least one element. A one-element array is considered
to be sorted. public class thirfd {
public static void main(String[] args) {
double[] arr1 = {16.1, 12.3,22.2, 14.4};
double[] arr2 = {1.5, 0.3, 7.0, 19.5, 25.1, 46.2};
isSorted(arr2);
System.out.println(isSorted(arr2));
[code]...
View Replies
View Related
Feb 13, 2014
I have spent some time thinking about the program, and realize I need two loops-- 1 that keeps track of bricks in a row and 1 that keeps track of the number of rows as the Pyramid rises in height. The Pyramid is supposed to be centered on the bottom of the screen. Three CONSTANTS have been required:
BRICK_WIDTH=30, BRICK_HEIGHT=12, BRICKS_IN_BASE=14.
I tried breaking the scope of things down by trying step-wise refinement. But, I got bogged down. When I tried a method where both loops were included, I got limited success. For some reason, my equation to center along the x axis seems to be doubling the number of bricks. But, the correct number of total rows of bricks was a success. Also, the Pyramid was centered on the bottom of the screen. Another frustrating failure was that the number of bricks would not decrease as the new layers were created. My thought process was instead of using a loop that counts up (i++) I would use a loop that counts down (j--) which I thought would reduce the number of brick in each row as the "y" coordinate was reduced by each count of the BRICK_HEIGHT.
This is the code that "works". Whenever I add the (j--) the results are NOT what I expect.
/*
* File: Pyramid.java
* Name:
* Section Leader:
* ------------------
* This file is the starter file for the Pyramid problem.
* It includes definitions of the constants that match the sample run in the assignment,
* but you should make sure that changing these values causes the generated display to change accordingly.
*
[code].....
View Replies
View Related
Feb 18, 2014
here's my code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class Milimetri extends JFrame {
private JPanel p1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
private JPanel p2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
private JPanel p3 = new JPanel(new FlowLayout(FlowLayout.LEFT));
[code]...
When i write a value in meters ..and press the button b1 to show me a value in milimeters..
View Replies
View Related
Feb 2, 2015
I am trying to make a custom table for a DB and i am stuck.
I want only the first column to have a checkbox and others not.
Is there a better way to insert the values instead using the getValueAt ?
@Override
public Object getValueAt(int row, int col)
{
if (col == 0)
[Code].....
View Replies
View Related
Nov 4, 2013
my application (java 6 RedHat 5.3 x64 ) using clean content jar for extracting data from email messages with attachments (doc, xls, ptt ...etc) After update from CleanContent-2009.1.1.jar to CleanContent-2011.1.1.jar (and any newer version) CompilerThreads will stuck in some cases (pretty often) In that case CPU usage is 100% all time, even when all activities on application are finished.
I was able to isolate several messages and every time when I used CleanContent-2009.1.1.jar it works ok but always stuck with CleanContent-2011.1.1.jar or newer versions!
View Replies
View Related
Aug 1, 2014
The goal of this code was to create a program using main method java to analysis a piece text which has been entered from a user.
They do this by entering the text into a scanner which is then analysed by the program. The analysis is to produce word frequency, for example " This is a test" produces this results:
This is a test
1 letter words: 1
2 letter words: 1
3 letter words: 0
4 letter words: 2
5 letter words: 0
The bit that I'm stuck on is producing a mean/average, My mind telling to divide
counts.length
by
str.length
But I'm not the Best at java and I've tried to implement this but all I get are errors.
Code:
import java.util.Scanner;
public class While_Loop {
public static void main (String[] args) {
while(true){
[Code] .....
View Replies
View Related
Apr 13, 2014
I think I'm about 90% complete with this program but I'm stuck on my adding entries method. It gives me a runtime error which says:
Enter the name:
Bill
Exception in thread "main" java.lang.NullPointerException
at Phonebook.addEntry(Phonebook.java:70)
at Phonebook.main(Phonebook.java:49)
Here is my code:
/*
* This program asks the user for input for a name, phone number and notes up
* to 200 entries. It stores every contact in a file. Type 'h' for help while
* running this program.
*/
import java.util.Scanner;
import java.io.*;
[code]....
View Replies
View Related