Does an asynchronous call always create/call a new thread?

This is an interesting question. Asynchronous programming is a paradigm of programming that is principally single threaded, i.e. “following one thread of continuous execution”. You refer to javascript, so lets discuss that language, in the environment of a web browser. A web browser runs a single thread of javascript execution in each window, it handles … Read more

Spring @Async limit number of threads

If you are using Spring’s Java-configuration, your config class needs to implements AsyncConfigurer: @Configuration @EnableAsync public class AppConfig implements AsyncConfigurer { […] @Override public Executor getAsyncExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(2); executor.setMaxPoolSize(5); executor.setQueueCapacity(50); executor.setThreadNamePrefix(“MyExecutor-“); executor.initialize(); return executor; } } See @EnableAsync documentation for more details : http://docs.spring.io/spring/docs/3.1.x/javadoc-api/org/springframework/scheduling/annotation/EnableAsync.html

How to manage db connections on server?

Keeping a Connection open forever is a very bad idea. It doesn’t have an endless lifetime, your application may crash whenever the DB times out the connection and closes it. Best practice is to acquire and close Connection, Statement and ResultSet in the shortest possible scope to avoid resource leaks and potential application crashes caused … Read more

Simple Thread Sample Delphi

Yup, you declare a new type which inherits from TThread: TMyWorkerThread = class(TThread) end; Then you add a function override for Execute(): TMyWorkerThread = class(TThread) public procedure Execute; override; end; That procedure will be called when you start your thread. It will be executed in parallel with your main program. Let’s write it. procedure TMyWorkerThread.Execute; … Read more

How to detect and debug multi-threading problems?

Threading/concurrency problems are notoriously difficult to replicate – which is one of the reasons why you should design to avoid or at least minimize the probabilities. This is the reason immutable objects are so valuable. Try to isolate mutable objects to a single thread, and then carefully control the exchange of mutable objects between threads. … Read more

Workaround for ncurses multi-thread read and write

Without the thread-support, you’re out of luck for using curses functions in more than one thread. That’s because most of the curses calls use static or global data. The getch function for instance calls refresh which can update the whole screen—using the global pointers curscr and stdscr. The difference in the thread-support configuration is that … Read more

Canonical way to generate random numbers in Cython

Big pre-answer caveat: this answer recommends using C++ because the question specifically asks for a solution that runs without the GIL. If you don’t have this requirement (and you probably don’t…) then Numpy is the simplest and easiest solution. Provided that you’re generating large amounts of numbers at a time you will find Numpy perfectly … Read more