Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8935989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:06:49+00:00 2026-06-15T10:06:49+00:00

I am processing a File in java where i am counting the number of

  • 0

I am processing a File in java where i am counting the number of occurrences of a particular Filed in every line of that file Where i am starting a Thread for every Line
as shown below

input = new BufferedReader(new FileReader(new File(finaName)));
    String line = null;
    while ((line = input.readLine()) != null) {
FileThread t = new FileThread(line);
t.start();
    }

FileThread st = new FileThread();
System.out.println("Size"+st.list.size());

FileThread.java

public class FileThread extends Thread
List<String> list = new ArrayList<String>();

public FileThread(){}
public FileThread(String line){}
private String line = null;
    public void run() {
    String[] tokens = line.split("\\|", LIST.length);
            String Symbol = null;
            try {
            Symbol = tokens[4];
                    list.add(symbol);

            } catch (Throwable t1) {
                t1.printStackTrace();
            }


        }

The problem is that i am always getting the Size as 0 .
please see the sample output

BIM!A
BIM!B
BIM!C
BIM!D
Size0

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:06:50+00:00Added an answer on June 15, 2026 at 10:06 am

    I have made some changes in your code, that may help you

    public class FileThread extends Thread {
        private List<String> list = new ArrayList<String>();
        private boolean inThread = false;
        .......
        public int getListSize() {
            if(!inThread)
                return list != null ? list.size() : 0 ;
            else
                return 0;
        }
    
        public FileThread(String line) {
        }
    
        public void run() {
            inThread = true;
                 // You logic of the thread
            inThread = false;
        }
    
        public static void main(String args[]) throws IOException {
         ..............
    
         ..............
    
         ..............
            System.out.println("Size" + st.getListSize());
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For processing a searchlog file I'm writing a Java class that should read and
I'm using GAE[JAVA] to do some image processing. GAE will not allow write file
As part of the build I'm processing DocBook file that produces multiple HTML files
I am processing a flat file, with data in line by line format, like
I have a Java program that processes one file at a time. This Java
I have a Java process that opens a file using a FileReader. How can
I know of the Apache Commons IO library for file directory processing in Java.
I have an XML file that I am trying to search using Java. I
We have seperate Java instances program processing raw weblog like that: jvm instance 1
I have one activity/java file (Browsefile.java) that would obtain the absolute path of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.