Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a .Net equivalent to java.util.concurrent.Executor?

Have a long running set of discrete tasks: parsing 10s of thousands of lines from a text file, hydrating into objects, manipulating, and persisting.

If I were implementing this in Java, I suppose I might add a new task to an Executor for each line in the file or task per X lines (i.e. chunks).

For .Net, which is what I am using, I'm not so sure. I have a suspicion maybe CCR might be appropriate here, but I'm not familiar enough with it, which is why I pose this question.

Can CCR function in an equivalent fashion to Java Executors, or is there something else available?

Thanks

like image 210
gcbrink Avatar asked May 29 '09 20:05

gcbrink


People also ask

What is the difference between executor and ExecutorService?

Executor just executes stuff you give it. ExecutorService adds startup, shutdown, and the ability to wait for and look at the status of jobs you've submitted for execution on top of Executor (which it extends). This is a perfect answer, short and clear.

What is Java util concurrent executors?

The concurrent API in Java provides a feature known as an executor that initiates and controls the execution of threads. As such, an executor offers an alternative to managing threads using the thread class. At the core of an executor is the Executor interface.

How many types of Executors are there in Java?

There are five ways to execute the tasks asyncronously by using the ExecutorService interface provided Java 6.

What is ExecutorService used for?

The Java ExecutorService is a construct that allows you to pass a task to be executed by a thread asynchronously. The executor service creates and maintains a reusable pool of threads for executing submitted tasks.


2 Answers

You may want to look at the Task Parallel Library.

As of C# 5 this is built into the language using the async and await keywords.

like image 102
Matt Brunell Avatar answered Sep 20 '22 10:09

Matt Brunell


If you're going to ask a bunch of .NET people what's closest to being equivalent to Java Excecutors, it might not hurt to describe the distinguishing features of Java Executors. The person who knows your answer may not be any more familiar with Java than you are with .NET.

That said, if the already-mentioned Task Parallel Library is overkill for your needs, or you don't want to wait for .NET 4.0, perhaps ThreadPool.QueueUserWorkItem() would be what you're looking for.

like image 23
Joel Mueller Avatar answered Sep 21 '22 10:09

Joel Mueller