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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:02:56+00:00 2026-06-17T10:02:56+00:00

I have written a task to send a certain TCP message through a socket.

  • 0

I have written a task to send a certain TCP message through a socket. I have a file with a bunch of messages and some timestamps, so I programmed the task as a TimerTask, and I scheduled it with a Timer with the first message timestamp.

When it finishes, the task run method is over, but its associated thread remains, it’s not cancelled. If I try to reschedule the task with a new Time, I’m getting an exception telling me that I cannot reschedulle a schedulled or cancelled task.

I also tried cancellig it before rescheduling, but obviously, as the exception told, it remains the same problem.

I can’t schedule the task with a constant perior to let it repeat itself, because each message has a time and it is not constant.

How can I reschedule the TimerTask? And by the way, is there any way of waiting for the task to end, just as in socket communications when it blocks with ready method until a message arrives?

  • 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-17T10:02:58+00:00Added an answer on June 17, 2026 at 10:02 am

    A TimerTask is not designed to be rescheduled and it is the Timer that manages the (single) thread.

    Use one Timer and many new TimerTasks:

    Corresponding to each Timer object is a single background thread that is used to execute all of the timer’s tasks, sequentially ..

    After the last live reference to a Timer object goes away and all outstanding tasks have completed execution, the timer’s task execution thread [should] terminates gracefully (and becomes subject to garbage collection).

    [From each of the schedule methods:]

    Throws IllegalStateException if [the TimerTask] was already scheduled or cancelled, timer was cancelled, or timer thread terminated.

    If there are indeed many threads spawned by a single Timer, then that would be a bug which is unlikely: make sure there really is only one Timer object being used.

    The last question, of how to compose individual events into a workflow, should be a separate post.

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

Sidebar

Related Questions

I have been given the task of re-writing some libraries written in C# so
I have written a program in java which implements some task. I have handled
I have written a custom MSBuild task, call it TaskA, that parses a file
I have written an MSBuild task that makes use of third-party assemblies. When I
I'm using nant to build our product and have written a custom task to
I have written this code inside a servlet to delete certain records from three
Using Script Task, I have written a code to create a folder and create
I have written various C# console based applications, some of them long running some
I have written an MFC dialog based application which is launched by some another
I have written the code for creating a list out of some arrays shown

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.