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

  • Home
  • SEARCH
  • 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 8976623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:11:25+00:00 2026-06-15T19:11:25+00:00

Original program code to modify: / this method is called periodically and it takes

  • 0

Original program code to modify:

/this method is called periodically and it takes data from db, performs some ooperations on it, and puts the results in a file which is sent at the ends of all processing via ftp/

void pullData(){
    while(!stopped){
        rows= getRowsFromDb();

        for (row: rows){
            newRow= process(row);
            rowsContainer.add(newRow)
        }

        writeToFile(rowsContainer);
        sendFileSomewhere();
    }
}

Now this code has to be modified to allow the following commands to be issued to it: process only 1 row; skip 1 row (more commands to come later). To do this the application is put in suspended mode and it will not process rows until it get one of the 2 commands I outlined above. Also, it can be resumed from suspended mode and then it’s back to normal processing.

The question is not how to do this, but what is the right way to do it.

(1) Someone suggested boolean flags for each operation. This is a pretty bad idea. I recommend people avoid flags for many reasons (some may have been discussed on stack overflow as well).

(2) Another idea was to use a bool flag for isSuspended and enums for the commands. This is better than (1), but not a lot because app needs to check which command was the last one and if it is in suspended mode and act accoringly.

(3) I was thinking of breaking up the application and use the Strategy pattern. Each command would get it’s own method in the application. This is a bit more complicated, but to me it seems a lot cleaner.

What would you suggest (you don’t need to choose from the options I listed, I want to hear how you handled a similar situation)?

  • 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-15T19:11:27+00:00Added an answer on June 15, 2026 at 7:11 pm

    I would use an ExecutorService with tasks like

    private Future lastTask = null;
    
    // only run one task at a time.
    if (lastTask != null) lastTask.cancel(true);
    
    lastTask = executorService.submit(new ProcessOnRowRunnable());
    // or
    lastTask = executorService.submit(new ProcessPendingRowsAndStopRunnable());
    // or
    lastTask = executorService.submit(new ProcessAllRowsUntilCancelledRunnable())
    
    // later
    future.cancel(true);
    

    Note: Your loops have to honour interrupts or they won’t stop just because the thread has been interrupted. You can use

    while(conditions && !Thread.curentThread().isInterrupted()) {
         // do work
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

every c program is converted to machine code, if this binary is distributed. Since
I've been reading through the original ping program code ( http://www.ping127001.com/pingpage/ping.text ) out of
This piece of code is a simplified version of a program I would convert
[Original] I have a ListBox which has its ItemsSource (this is done in the
How could I modify the below code such that I could, for better readability
I have this code: private void ModifyButton_Click(object sender, RoutedEventArgs e) { ModifyButton.Content = Another
I try to modify FGallery (https://github.com/gdavis/FGallery-iPhone). I need it to read images from the
I need to perform some operations on a 2D array of values read from
I found this code online and tweaked it a bit for my need to
I have this code: #define _WIN32_WINNT 0x0500 #include <cstdlib> #include <iostream> #include <windows.h> using

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.