Read And Process File Using Thread?

Nov 4, 2014

I created a main class called X and two Y and Z classes.

Y and Z implements Runnable classes.

class X contains a static array A that can be accessed in Y and Z.

The Run () method of the class Y reads an input file and populates the vector A.

The Run () method of the Z class uses data stored into the vector A to process some data.

The objective of using threads in this problem is: as the vector A is filled in the Run () method of class Y, the Run () method of the class Z will processing the received values ​​in the vector A.

to do this I did the following calls in the main method of class X:

ObjectY y = new Y ();
Thready thread = new Thread (objectY);
threadY.start ();
ObjectZ new Z = Z ();
Threadz thread = new Thread (objectZ);
threadZ.start ();

is that correct? I'm getting the expected results, but dont know if the code is parallelized in fact.

View Replies


ADVERTISEMENT

RMI :: Using RMI To Wrap A Process That Is Not Thread Safe

Apr 3, 2013

I have a multi-threaded application but one function (A) I need to call, that is provided by a third party, is not thread safe. I need to make parallel calls to function (A) so my only option is to start multiple process that I can call from each of my main applications threads.

To do this I created a RMI interface between a the client and the remote process. On the server side I start multiple processes each assigned a different port. On the client side I have a queue manager that connects to the processes I started and builds a queue of them. It passes the client to the threads as needed so they can function in parallel.

I am new to Java development and have the following questions:

1. Each of the server processes require an init function to be run before providing the service. How do I setup the server processes to continue to run in memory listening for a a service request after running the init processes.

2. Is there a better implementation of what I am trying to do?

View Replies View Related

Heap Dump Generated With Read-write Permissions For Java Process Owner

Apr 14, 2014

I have a question regarding the permissions set for generated heap dumps.
 
I have some Jetty servers running on Linux (Java 6 64 bit / Java 7 64 bit) with the following Java arguments:
 
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=/opt/apps/heapdump
 
When there is a out-of-memory exception a heap dump is automatically generated by the JVM. But it seems that the heap dump permisions are set to read-write for owner only (600).

When I create files then they have by default read-write for owner and group/all read access (644).
 
$ ls -l
total 795432
-rw------- 1 bamboop bamboo 811322265 Apr 14 09:18 java_pid337.hprof
-rw-r--r-- 1 bamboop bamboo         6 Apr 14 12:57 test
 
Here the umask set for the server running the Java processes
 
$ umask 
0022

View Replies View Related

Each Thread Should Read Files From Different Folders

Apr 14, 2015

I need to read folder structure from the excle file and need to read all the files which are available inside folder structure.folder structure like below

c:Migrate
C:MigrateMigrateFiles
...
...
..etc.

I am ble to read files which is avalibale in all the folders with single thread,i want to read those files with multiple threads,each thread shoud reads the files from different folder. here how to read.

View Replies View Related

File I/O - How To Process Contents From Input File

Mar 22, 2014

So my assignment is to read these values from an input file which I previously created. The 10 values represent miles traveled and I convert them using some formula my prof gave me to get the total cost, and output both values to an output file.

My programming question is the first number on the input file isnt a mileage value its the number 10, which is the number of values to be processed, which we're supposed to use in order to control a for or while loop which we'll use to process the contents of the input file. How would I create a while or for loop and get it to skip the first value of the input file?

We're not allowed to use arrays for this assignment.

Also here's my code so far, and it says its not being able to find the file, I made sure the file name is exactly as saved, and its saved in the same directory as the java class that i created for this assignment so I don't see what the problem could be?

Here's my the class with the main method

import java.util.*;
import java.io.*;
 public class QudratullahMommandi_3_07 {
 public static void main (String[]args)

[Code] ....

This is the error message I get

----jGRASP exec: javac -g QudratullahMommandi_3_07.java

QudratullahMommandi_3_07.java:17: error: unreported exception FileNotFoundException; must be caught or declared to be thrown
Scanner input = new Scanner(inputSource);
^
1 error

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.

View Replies View Related

Ending Process Of Another Running Jar File

Apr 16, 2015

I am working on a management gui for a program. I have implemented the start server button. But now I need to get something working so that when I press stop server the javaw.exe process which is running the the other jar file is stopped and ended.

The gui is going to be using a javaw.exe as well and I don't want to end the entire thing.

I just want to end the javaw.exe process that is running the other jar file.

This is my code for starting it:

JButton btnNewButton_2 = new JButton("Start Server");
btnNewButton_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Runtime rt = Runtime.getRuntime();
try {
Process pr = rt.exec("java -jar DEDServer_release.jar");

[Code] ....

I just need to figure out what to do to stop it now.

View Replies View Related

Using Interface To Process A File And Return In Different Format

Jun 15, 2014

I'm working on an assignment where the program has to process a file and read every line then print it out in all caps. I'm pretty sure I have most of it written out, however, I am having trouble with my main method. I am supposed to call my go method in my FileProcessor class and have it use the StringProcessor interface to call my Upper class. I'm using an interface because I will be adding other classes later, but for now I am having trouble with implementing it all in my Driver class.

How do I declare a StringProcessor object in my Driver class and how can I use it so that it would create the file in all caps?

Here's my code so far:

Driver.java
import java.util.Scanner;
import java.io.FileNotFoundException;
import javax.swing.JFileChooser;
import java.io.File;

[Code].....

View Replies View Related

Swing/AWT/SWT :: What Is Event-dispatching Thread For GUIs And Why Use It Over Main Thread

Sep 20, 2014

I'm currently learning about Swing but I can't get my head round this piece of the code. Here is a simplified gui (not interested in the gui part but the execution)

public class SwingDemo implements ActionListener {
SwingDemo(){
JFrame jfrm = new JFrame("Simple gui pro");
//rest of code
public static void main(String[] args) {
new SwingDemo();
}

I get the above, create a new instance of SwingDemo in the main thread which starts up the gui through the constructor. However, then the tutorial says that I should avoid doing the above but do this instead:

public class SwingDemo implements ActionListener {
SwingDemo(){
JFrame jfrm = new JFrame("Simple gui pro");
//rest of code
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() { //why do this instead?
public void run(){
new SwingDemo();
}
});
}
}

Reading, it talks about an event-dispatching thread which has completely lost me... Why not just instantiate the object directly instead of creating another thread?

View Replies View Related

Java Runtime Get Result Output From Prompt / Large File - Process Will Hang

Aug 13, 2014

I am using java process to start a system command in windows

Runtime r = Runtime.getRuntime();
Process pr = r.exec(cmdString);

I want to get the prompt out put from cmdString = "cmd /c type fileSmallSize"->>>> It is ok the have the content of the file when file is small.

However, for a large file java process will hang and no Exception occurred, what is the problem?

The easiest testing you can try on the logging.properties file in java.

public static String executeCmdAndReturnPromptResult(String cmdString)
throws Exception {
LOGGER.entering(CLASSNAME,
"Entering executeCmdAndReturnPromptResult()", cmdString);
String cmd = cmdString;

[Code] ....

It seemed to me that the bufferSize is limited so that I can only have it less than a default one, how to increase it?

My question now is how to increase the size of buffer in order to read a larger InputStream ?
BufferedInputStream() default size is
private static int defaultCharBufferSize = 8192;
private static int defaultExpectedLineLength = 80;

How to make it larger and working? I tried to increase the defaultCharBufferSize to 500000000 but it did not work!

View Replies View Related

Passing 2 Sub Arrays Into Sorting Thread Then To A 3rd Thread Merge

Oct 17, 2014

im having an issue with the 3rd thread that are supposed to merge the two sorted sub arrays , i pass the 2 subarrays to my runnable function sortlist and they are renamed IntSortList 1 and 2 and th1.start() and th1.join() are called and it works fine, but then i have another runnable constructor that takes IntSortList 1 and 2 but it does take a runnable. below is the code in my main,

Runnable InSortlist1 = new sortList(data2p1);
Runnable InSortlist1 = new sortList(data2p1);
Thread th1 = new Thread (IntSortlist1);
Thread th2 = new Thread (IntSortlist2);
try
{
th1.start();
th1.join();

[code]....

View Replies View Related

Accessing A Variable Of A Thread From Another Thread

Jul 16, 2014

class A extends Thread
{
String str;

public void run( )
{
//random stuff
}
}

[Code]....

View Replies View Related

Read Text File Into Object Array And Creating Random Access File

Dec 8, 2014

I am working on a project that requires me to build a database with random access file, representing products, the base product contains a name (about 30 characters), a price (double), and a quantity (integer). I have worked on this project for probably 15+ hours and have tried so many things and feel like I've barley made any progress...

The part i am really struggling with is taking the data from the text file and creating an object array with it using the product class. Once ive accomplished that, i have to use that data to create a random access file with the data.

Here is the base Product class that must be used to create the objects for the array.

public class Product
{
public String pName;
public String stringName;
public double price;
public int quanity;

[Code] .....

And then here is the data from the text file that i must extract to use to create product objects.

Dill Seed,938,34
Mustard Seed,100,64
Coriander Powder,924,18
Turmeric,836,80
Cinnamon (Ground Korintje),951,10
Cinnamon (Ground) Xtra Hi Oil (2x),614,31
Cinnamon (Ground) High Oil (1X),682,19

These continue for about 40-50 entries, they are not separated by a blank line though i had to add those so it would display correctly, each entry is on its own line with name separated with spaces, then price after a comma, then quantity after the second comma.....

View Replies View Related

Read Text File Into Array Ask User To Save File And Print Data

Jul 14, 2014

New to programming. Am supposed to create a program that reads a text file (of integers) and computes a series of computations on these integers. I don't have the code for the integers in my code yet, (i know how to do those), but am struggling getting the array to simply print in the print writer. I have the user select a text file, read the file with a scanner, and then save the computations done from my code into another file. specifically, the problem is as follows: Write a program that uses a file chooser dialog to select a file containing some integers. The file contains an integer N followed by N integers. The program then uses a file chooser dialog to let the user specify the name and location of an output file to write results to.The data written to the output file will be as follows

(1) The original list of N numbers from the input file,
(2) The original list of N numbers printed in reverse order of how they appear
in the input file.
(3) The sum and average of these numbers,
(4) The minimum of all the numbers,
(5) The maximum of all the numbers.

[import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;

[Code]....

View Replies View Related

Read Input File And Create Output With Anagram For Words In File

Sep 24, 2014

Well my code is supposed to ask for an input file and then (ex: input.txt), read the input file and create an output.txt file with the anagram for the words in the file. Also it should be displayed on the screen. However my code doesn't display the anagram on screen or the output file!

Heres is the code:

import java.io.*;
import java.lang.*;
import java.util.*;

/* This program will read a file given by the user, read the words within the file and determine anagrams of the given words. If the file that the user inputs is empty, then the program will output "The input file is empty."
* The program will read the file line by line, counting the total number of words read. If there are more than 50 words, "There are more than 50 words."
* will be printed, and the program will terminate. After each line is read, the words in the line will be separated,punctuation characters will be removed, and upper case characters will be switched to lower case.
* If any word is larger than 12 characters, that word will not be considered in the total amount of words in the file and it will not be sorted.
* After each word is read, the letters will be sorted and stored into an array containing each
* word's 'signature'. After all the words have been read, words will be printed to the output file on the same line based upon their signature.
*/

public class Anagram {
//Creating constants for maximum words in file and maximum chars in word
public static final int MAX_CHARS = 12;
public static final int MAX_WORDS = 50;

[Code] ....

View Replies View Related

JSP :: How To Browse And Read A File In Page To Perform Encryption For File

Nov 12, 2014

I am trying to create a file browse option in my jsp and later after browsing, all i want to do is to read that file in my jsp without saving it into that database so that i can perform encryption for it and save that encrypted file later into my database. please provide reference link so that i can refer to some applications and and move ahead with my work.

View Replies View Related

JSP :: Read Log File And Trigger Email With Same File Attached

Apr 6, 2015

I want to read the contents of a log file present on the server, and trigger email along with the log file attached using JSP.

View Replies View Related

Read A File And Then Output Back To Same File On New Line

Jan 24, 2015

I am trying to write to a file but everything I have tried doesn't seem to work. What I want to do is read a file and then output back to the same file on a new line. The text file contains the sentence "Java is a programming language".

import java.util.Scanner;
import java.io.*;
class HW1B {
public static void main(String[] args) {
Scanner fileIn = null;
try {
fileIn = new Scanner (new FileInputStream("text.txt"));

[Code] ....

These are the errors :

HW1B.java:19: error: no suitable constructor found for Scanner(FileOutputStream)
fileOut = new Scanner (new FileOutputStream("text.txt"));
^
constructor Scanner.Scanner(Readable) is not applicable
(argument mismatch; FileOutputStream cannot be converted to Readable)
constructor Scanner.Scanner(InputStream) is not applicable

[Code] ....

Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
2 errors

View Replies View Related

Read File And Input Each Line Of File Into Array

Mar 21, 2015

I am trying to read a file and input each line of the file into an array. I have not set the array size as I was hoping to fill the array using a while loop. Unfortunately the scope of the array does to work inside the while loop so I am being told that the array 'students' has not been initialised even though it has just outside of the while loop. Is it possible to do what I am trying to without having the array initialised in the while loop as surely the array will be reset every time if it was in the while loop? Here is my code:

public static void students(String file) throws FileNotFoundException {
try {
File studentInfo = new File(file);
Scanner input = new Scanner(studentInfo);
String[] students;

[Code] ....

View Replies View Related

How To Access One Thread From Another Thread

Oct 8, 2014

How to access one thread from another thread?

View Replies View Related

Can't Read From A File

Apr 12, 2015

I am writing a program that needs to read from a file, but I can't even get it to open. I have tried saving the .txt file 2 different ways. First, I saved the file to my src/package folder. Then I tried just the src folder. Then I tried going through Import/general/filesystem/ and selecting the root directory. However, my program is still unable to open the file.

private void readFile(String filename){
Scanner file;
try {
file = new Scanner(new File(filename));
System.out.println(file);
file.close();
} catch (Exception e){
System.out.println("Could not find file");
}
}

What am I doing wrong? How/where should I put the file?

View Replies View Related

Read From Txt File - For Loop

Jul 13, 2014

I am trying to read from a file and storing them back in the file but its not working, I think the way I am reading is wrong or something. Is the for loop correct way ?

try {
in = new BufferedReader(new FileReader("Events_data.txt"));
for (int x = 0; x <= Events.length; x++) {
tid = in.read();
te = in.readLine();

[Code] .....

View Replies View Related

How To Read A File Correctly

Feb 13, 2014

So i am creating a File object which has a text file passed to it. I then try to do logic with it using a BufferedReader. However, I get a FileNotFoundException on the using my code below. The Error is on the BufferedReader line. I

Java Code: System.out.println("--Reading text file--");
File file = getFile(c,fileName) // Returns a File object.
System.out.println(file); // Shows me the file is looking correct. Displays contents to console.
BufferedReader br = new BufferedReader(new FileReader(file));
System.out.println("BUFFERED");
while((line = br.readLine()) != null) {
try {
// Do Logic
}
catch(Exception ex){
ex.printStackTrace();
}
br.close(); mh_sh_highlight_all('java');

View Replies View Related

Read From File Input

Oct 25, 2014

The program is reading from file input. how can I replace hate with love the file contains only one line.I hate programing!

Java Code:

[import java.util.Scanner;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class Program3 {
public static void main(String[] args) {
Scanner fileIn = null;

[code]...

View Replies View Related

Unable To Read File

Nov 27, 2014

You are given a text. Write a program which outputs its lines according to the following rules:

If line length is ≤ 55 characters, print it without any changes.
If the line length is > 55 characters, change it as follows:
Trim the line to 40 characters.
If there are spaces in the resulting string, trim it once again to the last space (the space should be trimmed too).
Add a string... <Read More> to the end of the resulting string and print it.

I felt as if I did do what they were asking, but for some reason, I'm getting "Sorry, Unable to read file!"."Instead of using file, I did use the location of the file name".Also, I've attached a image of the input looks like and the output.

My CODE:

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
public class Main {
public static void main (String[]args)
{
try{

[code]....

View Replies View Related

Read Excel File Into JTable

Feb 4, 2014

I need to get excel file into jtable . I'm searching for this problem for 1 weak and no results . I downloaded hssf packages and didn't make a change in reading...

View Replies View Related

Use TextIO Methods To Read File

Dec 2, 2014

For the unit 3 assignment, you must develop a program. that reads the file icecream.dat. This file is supplied in the Files for Unit 3 Assignment directory in Unit 3. You must use TextIO methods to read the file. As you read the file, count the total number of ice cream cones that were sold. (This is the same as the number of lines that you read from the file.) Also count the total number of "Strawberry" cones that were sold.

At the end of the program, print out the total number of cones, the number of Strawberry cones, and the percentage of cones that were Strawberry.To do this program, you have to know when to stop reading from the file. TextIO has a function named TextIO.eof() to check whether the entire file has been read. The value of this function is true if the entire file has been read. The value is false if there is more data in the file. You want to continue reading from the file as long as TextIO.eof() is false.

Note: Suppose that flavor is a variable of type String and you want to test whether its value is "Strawberry". To do this, test whether flavor.equals("Strawberry"). (Do not use == to test for equality of Strings.)

Each line of the file icecream.dat is an ice cream flavor such as "Vanilla" or "Strawberry." A line represents the sale of one ice cream cone of the given flavor.

You must complete your program, test, debug, and execute it. You must submit your java code file. The output of your program must be captured by either copying the content in the output window and pasting it into a text document that you submit along with your java code file, or by capturing the image of the screen which contains the output of your java program. In windows you can capture a screen shot with the Ctrl Alt and Print Screen key sequence. This image can then be pasted into a Word, WordPad, or OpenOffice document which can be submitted with your assignment.

For students using the programr service online. Make sure that you create both the TextIO.java and the icecream.dat files as java project files. I found it was easier to rename icecream.dat to icecream.txt for some reason. For students using Netbeans, use the same set of rules that were defined in Unit 2 to setup your project and incude the TextIO.java file as we did in unit 2. Also make sure that you copy the icecream.dat file into your project directory so that it can be found by your java program.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved