Issue Details (XML | Word | Printable)

Key: BATCH-274
Type: Sub-task Sub-task
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Dave Syer
Reporter: Gregory Kick
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Spring Batch
BATCH-670

Support Callable<ExitStatus>

Created: 08/Jan/08 02:44 PM   Updated: 23/Sep/08 07:10 PM
Component/s: Core
Affects Version/s: 1.0.0.m4
Fix Version/s: 2.0.0.M1

Time Tracking:
Original Estimate: 1d
Original Estimate - 1d
Remaining Estimate: 0d
Time Spent - 0.06d
Time Spent: 0.06d
Time Spent - 0.06d Time Not Required


 Description  « Hide
Tasklet is essentially the same interface as Callable<ExitStatus>

ExitStatus execute()
vs.
ExitStatus call()

It would seem to make more sense to reuse a common java interface rather than create a new one with unfamiliar vocabulary. It may even be reasonable in Java 1.4 as long as executing callables is wrapped in
try
{
ExitStatus = (ExitStatus)callable.call();
}
catch(ClassCastException e)
{
  throw new CallablesMustReturnExitStatusExceptionWithSomeHelpfulMessageTelingYouToFixItException();
}

This also has the added benefit of promoting thread-safe execution because the Callable interface specifically states that it may be run in a separate thread.

 All   Comments   Work Log   Change History   FishEye   Builds      Sort Order: Ascending order - Click to sort in descending order
Douglas C. Kaminsky added a comment - 08/Jan/08 07:37 PM
On face, this won't work - Callable doesn't exist before 1.5

Assuming Callable was available, this is a dangerous precedent: ItemProvider, for instance, could also be written as Callable<Object> according to the same logic. While I do believe the ability to safely define threaded job behavior is an important part of the direction of Spring Batch, I personally don't see the value in this.

Lucas Ward added a comment - 08/Jan/08 10:32 PM
I tend to agree with Doug, although for different reasons. Many of the changes in Milestone 4 will push the Tasklet into more of a supporting role, where it exists solely as a wrapper for legacy jobs that call stored procs or scripts. ChunkProvider/ItemReader and ItemProcessor are now taking more of a central role, and as Doug said, they really shouldn't be 'Callable' since they represent distinct Domain concepts.

However, there may be some merit to reusing the callable interface post 1.0, so perhaps it should be moved to fix version 1.1?

Gregory Kick added a comment - 09/Jan/08 09:23 AM
@Doug
It exists, just as a backport or part of doug lea's work, not part of the jdk. And the issue wasn't to replace Tasklet (although I probably would), the issue is to support Callable.

As for ItemProvider being Callable<Object> (or probably Callable<MyDomainObject>, I would argue against that because it breaks the symmetry of the api. The issue wasn't intended to be "use callable everywhere you have an interface with a single method taking no parameters," but rather use callable over tasklet because they both represent units of execution to be invoked by a supporting infrastructure.

@Lucas
Yeah, I do like the fact that we're going to be seeing tasklet a lot less, but really the only reason that i brought this up is that a lot of people know what a callable is and what it's used for, but nobody knows what a tasklet is. It's entirely a judgment call, but i thought that I'd suggest it.

Dave Syer added a comment - 11/Jan/08 12:25 PM
I think it would be reasonable to exptec that someone might write a wrapper for a Callable that turned it into a Tasklet. Since we are not supporting Java 5 yet, but we know we will be in the future, I would prefer to leave it until then, to avoid having to provide a separate build/module with Java 5 features. Our other usage of backport is deeply internal, so no client should notice it, but this would be quite a public change if we made it.

Dave Syer added a comment - 17/Jul/08 07:18 AM
Added CallableTaskletAdapter.