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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:33:59+00:00 2026-06-01T08:33:59+00:00

I wrote this code: ScheduledExecutorService ExtractorTimer=Executors.newScheduledThreadPool(1); final ScheduledFuture<?> SchedulerHandle; SchedulerHandle =ExtractorTimer.scheduleWithFixedDelay( new Runnable() {

  • 0

I wrote this code:

ScheduledExecutorService ExtractorTimer=Executors.newScheduledThreadPool(1);
final ScheduledFuture<?> SchedulerHandle;
SchedulerHandle =ExtractorTimer.scheduleWithFixedDelay(
    new Runnable() {
        public void run() {
            if(DB.buildConnection()){
                  SchedulerHandle.cancel(false);
            }
        }
     },0, 60,java.util.concurrent.TimeUnit.SECONDS);

It gives this:

Variable SchedulerHandle might not have benn initialized

What is the problem?
How can I fix it?

  • 1 1 Answer
  • 2 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-01T08:34:01+00:00Added an answer on June 1, 2026 at 8:34 am

    Because SchedulerHandle is final and you didn’t define it right away, your compiler warns you, that it might not been initialized in the run() method.
    Simply do:

    final ScheduledFuture SchedulerHandle = ExtractorTimer.scheduleWithFixedDelay(…

    Update: That was simply wrong. Let’s see, you want to call DB.buildConnection() every 60 seconds until it returns true. Unfortunately you can’t reference SchedulerHandle returned from scheduleWithFixedDelay() in the Runnable you call the method with, because the Runnable has to be defined first – but it doesn’t know what SchedulerHandle is, because it doesn’t exist at that point.

    So an alternative way of canceling the process is to terminate your ScheduledExecutorService, like so:

    ScheduledExecutorService ExtractorTimer=Executors.newScheduledThreadPool(1);
    final ScheduledFuture<?> SchedulerHandle;
    SchedulerHandle =ExtractorTimer.scheduleWithFixedDelay(
        new Runnable() {
            public void run() {
                if(DB.buildConnection()){
                      ExtractorTimer.shutdown();
                }
            }
        },0, 60,java.util.concurrent.TimeUnit.SECONDS);
    

    But note, that if you do this, you can’t reuse ExtractorTimer and any given task will be canceled! Future schedule()s will also not execute. The only way to make it useable again is to create a new ScheduledExecutorService – that’s the drawback of this approach.

    So if you are okay using ExtractorTimer only for this one task, everything should be fine.

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

Sidebar

Related Questions

i wrote this code: class A { public: A(){d=2.2;cout<<d;} A(double d):d(d){cout<<d;} double getD(){return d;}
I wrote this code: public double SumRootN(int root) { double result = 0; for
I wrote this code in order to make a soundboard like app public class
I have wrote this code for c# void SelectionSort() { clearFontColor(); int i, j,
I wrote this code require('Database.class.php'); function get_info (){ $db = new Database($config['server'], $config['user'], $config['pass'],
I wrote this code: public class CustomData { public int F1 { get; set;
I wrote this code: public class FileViewer extends JPanel implements ActionListener { /** *
I wrote this code in C# to encrypt a string with a key: private
I wrote this code. The constructor works normally, but in the destructor I get
I wrote this code that compiles on Solaris gcc it works fine too for

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.