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 8713699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:24:13+00:00 2026-06-13T05:24:13+00:00

I have a requirement in which I have to check whether any file exists

  • 0

I have a requirement in which I have to check whether any file exists in the folder. If yes, then I need to process it one by one. With my basic knowledge I have arrived to a code structure which I have posted below.

I’m creating an infinite loop and checking whether the file exists in that folder. If yes, then I’m creating a thread and processing it, else it waits for a min and checks again.

class sample {    
    synchronized int getNoOfFiles() {
        // get number of files in the folder
    }    
    synchronized void openFile() {
        // open one file
    }
    synchronized void getFileContents() {
        // get the file content
    }
    synchronized void processFileContent() {
        //performing some operation on file contents
    }    
    synchronized void closeFile() {
        //closing the file
    }    
    synchronized void deleteFile() {
        //delete the file
    }

}    
class Test {    
    public static void main(String args[]) {
        int flag=0;
        Sample obj = new Sample();
        while(1) {
            flag = obj.getNoOfFiles();    
            if(flag) {
                for(i=0;i<flag;i++) {
                    MyThread1 t1 = new MyThread1() {
                        public void run() {
                            obj.openFile();
                            obj.getFileContents();
                            obj.processFileContent();
                            obj.closeFile();
                            obj.deleteFile();
                        }
                    };    
                    t1.start();
                }
            }
            else {
                try {
                    Thread.sleep(60000);
                }
            }    
        }
    }    
}
  • 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-13T05:24:14+00:00Added an answer on June 13, 2026 at 5:24 am

    I would suggest using a ScheduledExecutorService:

    ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1);
    executor.scheduleAtFixedRate(new Runnable() {
            public void run()
            {
                obj.openFile();
                obj.getFileContents();
                obj.processFileContent();
                obj.closeFile();
                obj.deleteFile();
             }
        }, 0, 1, TimeUnit.MINUTES);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a requirement by which need to check validation between number of days
Good day, I have a requirement which i need to include a layout (actually
I have a unique requirement which I need to meet to with sitecore, and
I have a requirement where I need to check a pipe | in the
I have a Text file which contains data (4 to 5 paragraph) and then
I have a requirement which sounds like kind of simple but hard to implement
I have a data storage requirement which is an excellent candidate for single instance
I have requirement like, suppose I have a 'property' table which has 'ListingKey' field
I have a requirement to design an application which notifies/publishes, its subsystems to send
I have a requirement to design a Web Application which acts as a Facade

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.