Building DOM Object From Multiple Threads
May 21, 2014
My multi threaded application processes and loads records into an ECM repository. For reconcliation purposes , I am trying to build an XML format report with the results of the processing per record, while processing is underway per thread. The method below is called from every thread wvery time its ready to append an element to the DOM with the status.
public void writeReportLine(Element rptLine) {
// Write output to report file
synchronized (XMLReportHandler.class) {
reportOutput.getDocumentElement().appendChild(rptLine);
}
}
After all processing completes, the below method is called only once by every thread to write to the File on the file system:
public void writeToReportFile() {
synchronized (XMLReportHandler.class) {
try{
//write the content into xml file
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(reportOutput);
[Code] ....
The problem is that when under load, the threads just seem to hang while the transformer.transform(source, result) call keeps getting executed until there is an interrupt of some sort. I was able to examine a section of what was appended and it was status for records that had finished processing very early in the process based on my application logs. Once an interrupt is recieved , it looks like the threads recover.
View Replies
ADVERTISEMENT
Nov 23, 2014
building a game. the game is all about the multiple times table with levels. easy medium and difficulty. I dont even know where to begin and what is the codes to use or even the platform. what websites can be access etc and what is the big deal with code tags.
View Replies
View Related
Apr 18, 2014
Actually, i want to create multiple ball using multithreading.I have created a class 'CreateBall' and this class is making ball and second class 'Balls' is a Panel where the ball is display.But only one ball is being displayed.
Here is my code.......
CreateBall.java
import java.awt.*;
public class CreateBall implements Runnable
{
int px,py;
int w=20,h=20;
Graphics g;
public CreateBall(int px,int py)
[Code] .....
View Replies
View Related
Jun 19, 2014
I am very new to threading. I have a program that calls my api and gets data back in json format. Each request returns a row of data in json format. All together I need to retrieve about 2,000,000 rows a day which means 2,000,000 requests (I understand that this is bad design, but the system was not designed for this purpose it is just what I need to do for the next couple of weeks). When I tried running it on a single thread I was processing about 200 requests a minute which is much too slow. As a result I created 12 threads and I was processing 5500 rows a minutes which was a great improvement.
The problem was only about on average 90% of the rows were inserted into the database as I ran it a few times to make sure. Before each insert printed to a file each URL which was sent and then I checked to see if each insert statement was successful (returned 1 when executed ) and it all seems fine. Every time I run it it inserts about 90% but it does varies and it has never been a consistent number.
Essentially the code starts in main by creating 12 threads. Each thread's creates a run method which calls a new instance of MySQLPopulateHistData and passes a start and end integer which are used in the insert statement for ranges. I have done many system.out.println type testing and can see all the threads do start and all the 12 instances (one instance for each thread) called are executing?
MAIN:
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class MainClass {
public static void main(String[] args) {
[code]....
View Replies
View Related
Aug 23, 2014
I have a Swing UI in which on click of Search button, I trigger the Search in 6 different modules in 6 Swing Worker threads. The results are returned by each Swing Worker class to the calling class.
I tried to use the below code to get the values returned from each thread. Now, I want to continue further only after all threads finish their execution. How to achieve this?
thread1.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if (StateValue.DONE == thread1.getState()) {
try {
[Code] ....
I got several examples where the UI is updated direstly from multiple threads. I want the values to be returned to calling class because of below reasons:
1) When even one worker thread fails for some reason, I dont want to show the any result in the UI
2) Earlier, I was updating the UI in done() of every worker class. But, UI became inconsistent. E.g When one thread is in progress, other threads were completed and updating the UI which I dont want to do.
View Replies
View Related
Jun 30, 2014
I have a multithreaded application. I have a Logger class with static methods that I use across threads. Would it behoove me to add the synchronized keyword to the static methods of the Logger class since I use this class statically in different threads?
View Replies
View Related
Mar 24, 2014
I need a small example of an object which is visible to two different threads.
Does saying "an object is visible to two threads" mean that it's fields or methods are being used in both the threads? I am not clear about that.
View Replies
View Related
Apr 16, 2014
I know that below code would put a lock on current instance of DemoClass, What I am not sure of is the role of lock on Object Class in second example. How does below works - Is it putting a lock on Object Class? If yes how will putting a lock on Object? I mean, locking DemoClass ensure no two threads access it concurrently, how does this apply to Object class?
private final Object lock = new Object();
synchronized (lock)
public class DemoClass
{
public void demoMethod(){
synchronized (this)
[code]....
View Replies
View Related
Dec 27, 2014
I am reading Head First: Java and got to Object References. In the book I got a little bit confused on what happens when two object reference's point at the same object so I wrote a small crude test, the below code. This of course clarified what happens but what I am interested in knowing is in what circumstances would you want to have two separate references for the same object when you could just use the original? Eg. v1
class ObjectValue{
int objVal = 1;
}
class ObjectValueTestDrive{
public static void main(String [] args){
// "Value of v# should be" refers to if it copied the given object values, instead of referencing the same object
ObjectValue v1 = new ObjectValue();
System.out.println("Value of v1 should be 1:" + " "+ v1.objVal);
[code]....
View Replies
View Related
Dec 10, 2014
My application needs to accept multiple input at different time and i need to serialize it whenever it gets the new input and after that i need to Deserialize the object one by one.how it can be implemented. Eachtime i am able to deserialize only one object that came at last. How to implement this functionality..
This is the code for serializing.
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Scanner;
public class Dummyserial implements Serializable {
[Code] ....
View Replies
View Related
Apr 15, 2014
I am trying to make a pyramid from blocks . I know that for example to make a bigger block from small blocks you write something like :
for(int i = 10 ;i <=1 ; i--){
for (int j= 10 ;j <= 1 ; j--) {
< statement to create block where you use both i and j to define the location of each block>
}
}
but i cant seem go grasp how to make a pyramid , so far my best effort is :
int i =10 ;
while (i >=1 ) {
for( ; i>=1 ; i-- ){
< statement to create block > }
}
At the moment visually i don't get a pyramid but it might be because of other issues and not because of the while and then a for inside it approach .
My approach is correct and if now what would be the correct one to create a pyramid from smaller blocks ?
View Replies
View Related
Jan 18, 2015
I'm assigned along with two others to make this program for a project.
We need to store data to the program by adding them such as user_id among the 5 criterias that are needed. Lets say I want a new user, I need the program to give me that option and then I would type in the user id and the program would store that data information
As far as I'm aware, boolean, screentokenizer and scanner is involved in the making of this program.
View Replies
View Related
May 28, 2014
I have to write a program for class that basically uses Paint Component to draw a bunch of rectangles to look like a building then have them change color randomly. I am stuck I can't figure out how to make it draw the rectangles in rows and columns to look like the building i can make it display multiple squares randomly however but thats not the assignment.. here is my code
package labBuilding;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
@SuppressWarnings("serial")
public class Building extends JPanel {
[code]....
View Replies
View Related
Mar 30, 2014
I'm having this where i'm trying to return a JPanel with tempPictures but only if they aren't already filled with "actual" pictures. However this causes problems because your never shore that the if statement will execute. I tried adding an else statement but i cant return null i must return a JPanel;
private JPanel buildTopShelf() {
if(myMediaHandler.mediaList.size() < 6) {
JPanel mediaPanel = new JPanel();
mediaPanel.setOpaque(false);
mediaPanel.setLayout(new GridLayout(1,6,22,0));
mediaPanel.setBounds(90, 14, 1020, 210);
[Code] ....
View Replies
View Related
Dec 18, 2014
i'm totally new to Java.I'm making a small text based RPG and this is what i've come up for now.
Java Code:
import java.util.Scanner;
class Main {
public static void main(String args[]){
Scanner input = new Scanner(System.in);
Player playerObject = new Player();
[code]....
My thing is that i want the user to enter 'Caucasian' or another race in the console below and i want it to be saved in a variable or something else in the Player Class that i can later use it in texts or something else. My question is how can i do it?
I tried like 'int Mongoloid = 1; int Caucasian = 2;'
And the same with the others, and after that i tried to use them with the Switch Statement but it did not work.
View Replies
View Related
Apr 22, 2015
How to create object for "class B" and call the "function_B" from other different class D where class D has no connection with class A? Here is my program.
public class A(){
void print(){}
}
class B{
void function_B(){}
}
class C{
void function_C(){}
}
Here, A, B, C are in the same package. But class D is in different package.
View Replies
View Related
Jul 13, 2014
I'm trying to build a binary tree using two arrays I'm given, one is inorder and the other is postorder and I have to construct the tree based on that. I understand the strategy I need to use- the last element of the postorder array tells me the root node, and wherever the value of that node occurs in the inorder array is where the tree is split. I can then apply this idea recursively to build the tree. For whatever reason though, I keep getting stack overflows.
Here's what I have so far:
public static class TreeNode {
char val;
TreeNode left;
TreeNode right;
TreeNode(char newVal) {
val = newVal;
[Code] .....
View Replies
View Related
Apr 4, 2014
Every year, she has to plan when her employee's can go on vacation for the summer holidays - MANUALLY. It takes weeks to solve the puzzle, because she has several kinds of employee's hired, with different skills. And at all days there must be X amount of employees with skill1 at work, plus Y amount of employees with skill2 etc, and they also need special "off-days" in comparison to when they last worked and so on. It's quite the math puzzle.
I've worked a little with C#, and built a prototype of a Support System (Ticket based), so I got the basics down of programming, and I know Java and C# are quite alike, so I don't think making the switch will bother me that much.
The program should be easy to use for her, so it needs a visual calender that can be interacted with, and it should also be easy to see which employee is at work at that date and so on.
Will it be hard for me to build this kind of Calender, that allows the interaction I want?
Any open-sourced projects, or libraries that will make my task easier?
I plan on using NetBeans IDE for this project.
View Replies
View Related
Jan 17, 2014
I'm trying to build a program that would present the user (well...me) with a rather large list of various check boxes (and combo boxes, etc...but for sake of the question I'll limit it to check boxes) and the selections would not only need to be stored in some way so they could be reloaded, but also they would need to have the "data" used to build sentences.
For example, part of the form would have a checkbox list like:
Emotional Issues -
Emotion 1, Emotion 2...Emotion 40
Then, at the end of the form I would be able to save client, load client, or generate report. When doing the generate it would output something like:
"Client's first name reported having emotional disturbance in areas of 'Emotion 1', 'Emotion 4', and 'Emotion 12'."
There, of course, would be probably several hundred check boxes, combo boxes, etc. throughout this program building a rather complex "report" when it's all said and done. So where I am stumped in on the methodology or approach that would be best for getting, storing, retrieving, and outputting this information.
View Replies
View Related
Nov 17, 2014
Implement an applet that display historical facts. The applet will include facts from october 28 to december 4th to test the applet.
What is the best thing to add text in my GUI - JLabel, JTextArea? I am trying to display different words on my csFacts. Once a user click button yesterday and button tomorrow?
public class Facts extends JFrame implements ActionListener{
private JButton button1,button2;
private JPanel panel;
private JLabel label;
TextField ri = new TextField(50);
private void createGUI(){
setDefaultCloseOperation(EXIT_ON_CLOSE);
[Code] .....
View Replies
View Related
Jun 17, 2014
The goal of this software is to provide a web interface which must be able to manage the Quagga routing daemon. For those who don't know Quagga, the only interface it provides the user is its built-in cli. My project must convert web events to commands and vice-versa. how I'm going to maintain quagga's configuration state synchronized with JSF's managed beans. The example below shows the commands one must run on quagga's cli in order to add a BGP neighbor:
neighbor 10.0.0.1 remote-as 65535
neighbor 10.0.0.1 description "Just a Test"
neighbor 10.0.0.1 next-hop-self
neighbor 10.0.0.1 soft-reconfiguration inbound
write memory
In order to represent this piece of information in my project, I was thinking about mapping this to a class:
public class BGPNeighbor {
private String ip_address;
private Integer asn;
private Boolean next_hop_self;
private Boolean inbound_soft_reconfiguration;
}
With this I would parse the information from Quagga's configuration and map this to classes in my software. I think it's a lot easier to do with database-based software, the problem with this project is that it's not completely database oriented. The information must be fetched from the network, parsed, converted to classes and then they would be available to JSF as managed beans. Any alteration to this classes must be converted to quagga cli commands which must be executed through the network again (telnet).
View Replies
View Related
Nov 20, 2014
My assignment was to create a simple form that demonstrates the use of the factory and singleton design patterns. "Use the Factory pattern to ensure that each form input consists of a text label and a textfield. Use the Singleton pattern for the submit button."
Here's what I have:
Form.java file
interface Form {
public void getFormField ();
}
Name.java file (I have a similar files just like this for Address.java, City.java, State.java, Zip.java and Phone.java)
import java.util.Scanner;
class Name implements Form
[Code] ....
It compiles at the moment but I get a null pointer exception in the main method of the FormFactoryDemo file.
View Replies
View Related
Apr 20, 2014
I'm new to Java and trying to write code a Java program on Mac OS X using IntelliJ. My program uses the SWT library and contains two class's; the first called "view" and the second called "main". The "view" class defines the SWT objects, extends the "Thread" class and contains a "run" method;
public void run() {
initComponents();
while (!display.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
[code]....
I searched for a solution and saw that I have to use the "-XstartOnFirstThread" parameter to JVM. I'm trying it with no success.
View Replies
View Related
Apr 28, 2014
I making a program that a client connect to a server, then it's starts changing information throw the socket. The info is String. When connection with one open client everything is working great. The problem starts when I connect 2 or more clients simultaneously.
The server doesn't know how to handle each request so it's send info to both the client info that is wrong. If I run several clients and then execute the last client that opens he will work fine the others will crush. On the server I'm getting connection reset. The problem i believe is with the closing socket and thread holding.
View Replies
View Related
Dec 8, 2014
I have i am trying to implement tooltip through javascript, like when we click on an image link tooltip should be displayed and it should have close button/ close image to close that tooltip.like the same way i will have multiple images on page, when ever i click on the images all tooltips should be displayed on the page when ever i want to close that then only it should close through close button on tooltip.can we do it through java script or will go for jquery.
View Replies
View Related
May 5, 2015
I'm very new to Java, and I am creating a program that takes multiple user input to create one face. I have a class for the eyes, nose, lips, and headshape. For some reason, my program is not drawing the graphics. ***for question purposes, I have only included my head shape class and my test class****
my "test" class:
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class FaceTest
{
public static void main(String[] args)
{
String head = JOptionPane.showInputDialog("Would you like a circle, square, rectangle shaped head?: ");
[Code] ....
View Replies
View Related