Callable Dao dynamic method

I need to do something like this:

Creating a callable, and pass it to a ThreadPoolExecutor. The Callable in fact is a Dao, which should execute different functions. Because its not possible to pass parameters to the call() function directly, i thought about doing something like this, to immediately execute the code when an object is created:

Creating a class like this:

public class FooRecordDatabaseInsert {
    static {
        //execute some code

The callable could now look something like this:

    public Foo call() {

But i have to pass parameters, like an Entity to this class. Is there a good possibility to create a class which has one function with parameters, which is immediately executed, when the object is created?

Or may there be an completely different solution?


If I understand correctly, you want a Callable that calls a method of a DAO with parameters.

So you want something like this:

final MyDAO dao = ...;
Callable<Foo> callable = new Callable<>() {
    public Foo call() {
        return dao.someMethod(1, 2, 3);

This is called an anonymous inner class, and you should definitely know about them before doing advanced, complex, multi-threading stuff.

With Java 8, you can use lambdas to make things even simpler:

MyDAO dao = ...;
Callable<Foo> callable = () -> dao.someMethod(1, 2, 3);

Need Your Help

Dialog Class doesn't let me interact with CButton on the dialog?

c++ visual-c++ mfc

If I create the CButton in the myTab class, I can't interact with it as a user.

sound effect for jQuery UI Easing plugin

jquery jquery-ui

I am using jQuery UI Easing plugin and would like to have corresponding sound effect when animation happens. How can I possibly do that ?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.