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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:08:18+00:00 2026-05-21T15:08:18+00:00

I’m still somewhat new to multithreading so maybe this is an easy answer, but

  • 0

I’m still somewhat new to multithreading so maybe this is an easy answer, but I tried searching around with locks and synchronized methods but this isn’t working out right.

I have a system which connects to an ftp site and downloads an xml file to process. The application waits until the file on the ftp site is updated, if it isn’t updated it doesn’t do anything. If it is updated it downloads the xml file to start processing.

Before we process the xml we check the version of a file on the server, and the version of something in the database, if the versions aren’t the same, create a new thread and update the file on the server to the new version.

So in code it’s pretty much:

if(file.version.equals(db.version))
{ 
  do work...
}
else 
{
  startUpdateThread();
}

private synchronized void startUpdateThread()
{
   Runnable updateRunnable = new UpdateRunnable();
   Thread updateThread = new Thread(updateRunnable);
   updateThread.start();
}

The problem I’m having is that the xml file will change on the ftp site in the middle of updating the file on the server and still enter the startUpdateThread() method and by the time it’s finished I will have multiple threads trying to accomplish the same tasks.

My question I guess is, why is the syncrhonized method still being called even though it should be locked, and if I’m doing it wrong what is the correct way to approach this without creating multiple threads to accomplish the same tasks.

edit
A little further explanation of the system, the file on the server gets loaded into a cache when the application starts, so the file.version.equals is really from a cache. The file only needs to be regenerated once every few months it’s something that is done manually that I am going to make automated.

The file on the server and the xml file have nothing to do with each other, it just happens that this check is triggered when the application see’s the file on the server has changed (which is roughly every two minutes). To generate a new file and load it into cache takes about 10 minutes. So the check happens about 5 times, thus creating 5 threads, regenerating a file.

The desired result is:

Normal processing to continue with the xml file

ONE new thread being created to reload a totally seperate file on the server.

Hopefully that makes better sense…

  • 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-05-21T15:08:19+00:00Added an answer on May 21, 2026 at 3:08 pm

    Of course – the method startUpdateThread() is syncronized but not the actual execution of the threads. The lock is released when the updateThread.start() call terminates – and this is long before the worker thread finishes.

    Question is, what is your desired behaviour: if the remote file changes while you process it, then it is my understanding, that the changed file has a different number.

    You could send a signal to the running worker thread to stop processing that file because it is already outdated. Or do you want the “second” worker thread to wait until the first one has finished? In that case, a ThreadPool with size 1 could help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.