maidh91 / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Simplifing job concurrency #386

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Some times run some process many time ( concurrently ) on diferent data could 
be really painfull.

We could have some object that dispatches jobs in threads have fluent/simple 
utilization.
This object could provide methods to configure the dispatching like the number 
of concurrent threads.

An exemple of this:

List<String> data = Arrays.asList( "abc","def","ghi","jkl" );

        ConcurrentJobDispatcher.create()
            /* Data to be provided to each job
             We could have a lot of differents data providers
             for Collections for Suppliers 
             or even the final developer could write 
             a own implementation of DataProvider interface
             ( providing hashNextData() and nextData() methods )*/
            .withDataProvider( DataProviders.from( data ) ) 
            /*
                * Number of simultaneous threads 
             * */
            .withConcurrencyLevel( 5 )
            /*
            * Code to be executed on the threads 
               */
            .withJob( new ConcurrentJob<String>() {
            @Override
            public void run( String data ) {
                   System.out.println( data )                           }
            } )
            /*
             * Starts the dispatcher and block the caller threads
             * ( could also have a executeInBackground() or only execute() )  
             */
            .executeAndWait();

Original issue reported on code.google.com by hood...@gmail.com on 20 Jul 2010 at 11:48

GoogleCodeExporter commented 9 years ago
I agree that could be useful. It also feels a bit out of scope with respect to 
Guava. But thanks for sharing!

Original comment by fry@google.com on 28 Jan 2011 at 9:24

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:09