How to Stop a Thread

There is no direct method to stop a thread. Earlier there used to be methods like Thread.stop(), however now these are deprecated. So how can we stop a thread if there is no 'stop' method?

To understand the answer, we first need to understand the thread and its working. For understanding the thread, please refer to other post 'What is Thread'. So one thread performs a assigned work at a time and its life is over once this work is done. Like if we take example quoted in 'What is Thread' post, then a painting work assigned to a sub-contractor is the life of relation with him. As soon as, he will complete his painting work, the sub-contracting relation will end. 

So the right way to stop a thread is to complete its work, or to make it understand that its work is over and it has to exit. For example, Painting contractor can ask the sub-contractor painter while assigning the job that please work till you finish painting in this service or till I call you to come out of this room. So the sub-contractor will start painting and will automatically exit from the relation as soon as it will finish the painting. Alternatively Painting Contractor can call him in-between and so the sub-contractor will keep on checking that whether the contractor is calling him or not. If not, he will continue with his work till its completion. If yes, he will leave the work and exit the room. 

What is Thread

A thread is a fork of a computer program in two or more concurrently running tasks. Let us try to understand it with example, 
  • Process: It is generally a single program in computer. Like, You need to get your house painted. So you hire a painting contractor and make a contract for painting your house. Now this painting contractor will get the house painted. So we can equate it with a process which, once start, will paint the home. Suppose you also want to change the flooring of your home, then you will hire some other contractor for this work. This will be another process which will do the flooring work. 
  • Threads: Now if the painting contractor paint the whole house himself single handedly, it will take him many days. But he as well as you want to get your work done ASAP. The solution is that contractor uses multiple sub-contractor under his control and use them to paint the house. These sub-contractors work simultaneously on different portion of the tasks. These sub-contractors can share the resources, i.e. will be using the resources from same pool. Now as multiple sub-contractors are working in parallel on multiple tasks, it will speed up the whole process and whole house will be painted in much lesser time. So these multiple sub-contractors are like threads in main process (painting contract).

Surya Namaskar - One of the Best and Easy Way to Ensure Good Health for Inner and Outer Body

Surya Namaskar (Salutation to Sun) is a Yogic Exercise and is a sequence of different Yoga Postures (asanas). It is used to worship the Surya (Sun) at the time of sun rise (can be done in evening when sun sets). It has diverse effect on all aspect of human body and the living of the human. It is very good for physical and mental health, and an easy way to ensure the good health of both outer and inner body. If one can be regular with Surya Namaskar, it can make a lot of difference in her life. Surya Namaskar can be done just for ensuring the physical health i.e. in the form of simple physical exercise. In this state, it will help to ensure a good health for body. However further it can be used as a medium for Sadhana by using asanas, pranayam, mantra and focusing on energy sources in body (sever energy chakra). It is very helpful in Sadhana (a mean to achieve something, mostly through spiritual practice).

Surya Pranam (Namaskar) is believed to be an exercise to gather the energy from Universe.

Initializing Parsley Framework and Dynamic Short Lived Objects

Parsley framework needs the configuration file for its initalization. This configuration can be written in tradition mxml file or using a xml file. Parsley API provides different configuration builders for initializing the configuration from these files, like FlexContextBuilder and XmlContextBuilder etc. So step to initialize the Parsley are:

  • Create configuration file either in mxml file or in xml file
  • Call appropraiate API by using the above file
    • or
    • etc
  • The build method will always return a context object. 
Generally we need  not to use the context object directly. Parsley itself manage the creation of objects and their relations through injection by using the declared configuration. However in some situations, we may need to interact with the API, like if we are extending the framework for some custom requirement, or for creating the application test environment etc.

Once we build the configuration, the Parsley environment is ready with the context and other configurations mentioned with configuration file. Now suppose if we are preparing a test case and want to fire the events from it so that respective command can be executed based on these events. Here the requirement is to attach the test case object to Parsley context, so that test case object gets the support of event mechanism from Parsley. The way to attach the object with Parsley is to add the object in context. 

Generally for short lived objects, we should use Dynamic Context. Dynamic Context should always be created from default context, so that it can be wired with the other application context. 

dynamicContext as DynamicContext = Context.createDynamicContext();

Now add the test object to this dynamic context. This can be done in setup of the test case. We should consider to remove the object from context after execution of the test methods. Code will be as:


Now the test case object is linked with Parsley and hence live for Parsley. Now it can participate in all life cycle events and operations of the Parsley like event firing and management. 

Importance of Context Object in Parsley

Context is the heart of Parsley Framework which keep every other part/object of the framework alive. So any object, which want to live in Parsley environment, should be linked with its Context. Any object which is not linked to context is not actually live for Parsley, as no body part can live without supply from heart.

Above is the artistic definition. The technical point is that, context is the object where Parsley framework keeps all the information for all linked objects. Context is the single shared object among all the components, and parts of the Parsley. So if any part of parsley needs any object, it can ask the single shared context for the object. Similarly, context is important in initialization and un-initialization of objects and manage their life cycle events as well.

So context is the storage of all the live objects in Parsley framework. Any object can be asked from the context at anytime during execution.

And the object, which is not in context, is not live for Parsley.

Now Parsley features are available to the objects only which are live i.e. if their existence is known to Parsley framework. For example, only those objects can dispatch and consume the events which are live for parsley. Similarly dependency injection will also work till the object is in context. Many a times, developers face the problem like their object is either not dispatching the event or not consuming the event, a major debug point can be to ensure that this object is still in context of Parsley. Objects can be released from Parsley context due to various reasons like

  • Dynamic commands releases from context as soon as these get the result or error from service call.
  • View objects releases from the context as soon as their parent window gets closed

So be careful for the object life cycle and always code to consume all the events before the un-initialization of the objects.

What is XML

XML is a strong and flexible language.

As soon as we read the word ‘language’, most of the persons, new to XML, consider it as some programming language and start wondering what all we can create using XML language.

But Friends, XML is not a programming language but it is a language. Language means a way of communication which can communicate the intended message to the other partners, which can make them understand what we want to say. It is like any other language which used to have a grammar to write and read the messages.

XML works in similar fashion. It does have its own protocol i.e. defined set of rules (grammar) that how one should write and read the messages using XML. 

Tips for E-Mail Communication

Here are a few points which may be helpful for mail communication:

  • Subject of the mail should be chosen wisely. 
    1. It should explain the motive of mail, i.e. receiver should understand from the subject itself that why this mail is here and what would the purpose, and even sometime, what is the expected from her.
    2. It should not be too big
    3. It should not be generic like Hi , until you don’t have any other choice after much thinking.
  • Mail should be started with formal salutation. It put the reader in good mood with the start of the letter. Like
    1. Hi/Hello - If you interact quite often
    2. Dear Mr/Ms - More formal communication
  • Writing a name directly to start the mail is not always recommended i.e.
    1. 'Name'
      1. Please do the work as discussed.

Use of Prepared Statement and Stored Procedure

What is the use of Prepared Statement or Stored Procedure? When should we use simple statement, prepared statement or stored procedure?

To understand the answer for above questions, we first need to understand that how database systems manage and execute the query. When we ask database system to execute any query, there are few steps in execution. Major steps are

  • Parsing of query
  • Compilation
  • Execution
Database system parses the supplied query; hence break it to the tokens to understand what is being supplied. Compilation step process the parsed tokens and create the execution structure which can be database specific. Mostly these are the expressions which evaluate the query tokens during execution. For example: