0

I wonder if after the FutureTask finishes his job and I can get the result from it successfully, should I cleanup the FutureTask to release the resource ? Or the FutureTask will be cleaned up automatically after a certain amount of time after it finished the job ?

Thank you.

Xitrum
  • 7,765
  • 26
  • 90
  • 126
  • 1
    That probably depends on what the result of the task is. If it's some pojo you probably just drop all references you're holding to let gc do its work like you'd do with other pojos. If the future holds a reference to a closeable resource like a stream you might have to close it - or think about why the future holds such a resource in the first place. – Thomas Apr 11 '16 at 12:09

1 Answers1

2


The FutureTask is kind of immutable. Once its value, and state have been set they cannot be changed. Apart from this, the FutureTask is like any other Java object, so you don't have to do anything. It is eligible for GC as soon as there are no more references to it. This means, it will be GCed once it goes out of scope, or if you insist you can remove the reference by assigning null to it. If you have written your code well, you shouldn't set null to any reference - every object should live in the smallest scope possible.

Boyan
  • 589
  • 5
  • 19