Showing posts with label Threading. Show all posts
Showing posts with label Threading. Show all posts

Thursday, 10 November 2011

Java/J2EE interview questions: - Explanation of working thread .

One can start answering this Java/J2EE interview questions as follows: -
  • In working thread scheme, allocates one thread to execute one task.
  • When the task is complete, the thread may return to a thread pool for later use. In this scheme a thread may execute arbitrary tasks, which are passed in the form of a Runnable method argument, typically execute().
  • The runnable tasks are usually stored in a queue until a thread host is available to run them.
  • The worker thread design pattern is usually used to handle many concurrent tasks where it is not important which finishes first and no single task needs to be coordinated with another. The task queue controls how many threads run concurrently to improve the overall performance of the system. However, a worker thread framework requires relatively complex programming to set up, so should not be used where simpler threading techniques can achieve similar results.
View the following video on tiles integration with Struts 2: -



Know more on Java interview questions

Regards,

Get more on Java interview questions from author’s blog

Saturday, 29 October 2011

Java/J2EE interview questions: - How would you create a thread pool in Java/J2EE??

While facing Java/J2EE interview questions you may come across this question by the interviewer. So you can your start with the answer as follows.

public class ThreadPool implements ThreadPoolInt.

This class is an generic implementation of a thread pool, which takes the following input: -
  • Size of the pool to be constructed.
  • Name of the class which implements Runnable and constructs a thread pool with active threads that are waiting for activation. Once the threads have finished processing they come back and wait once again in the pool.
This thread pool engine can be locked i.e. if some internal operation is performed on the pool then it is preferable that the thread engine be locked. Locking ensures that no new threads are issued by the engine. However, the currently executing threads are allowed to continue till they come back to the passive Pool.

Interested to learn more, then view the following detailed video on Java Builder pattern which is also asked during Java/J2EE interview questions: -



Visit for more Java/J2EE interview questions series.

Regards,

Also visit author’s blog for more Java/J2EE interview questions