If you are talking just about Web Applications then I would say you should tread lightly when using threads - you may not want to use them at all but if you do make your own threads then make sure you absolutely need to.
But either way your Web Application will be using multiple threads and so you have to worry about save data management, synchronization, and how data is shared across requests.
why to use thread in application, when already we can use servlet and jsp which are multhithreaded?
Thanks in advance
Sometimes you need to manage tasks behind the scenes, you need to create thrads and be responsible for making your applications (web or desktop) as efficient as posible, threading not only gives you better performance but gives you the chance to write more complex and robust applications
The web applications are multi-threaded, so we don't need to explicitly use threads there but all the applications that we develop are not web applications that use JSP or Servlets.
Threads are used when you want to execute two or more tasks in parallel. One example where threads are required could be an application where the application loads something from the internet on the startup and we want the loading icon to come during the loading time. Here there are two tasks running in parallel. Suppose we have a function public void loadFromInternet() that loads the data from internet and we have one more function public void showLoadingScreen() that shows the loading icon. Now if we call the loadFromInternet() and showLoadingScreen() function one after the other, then the first of all, the data will be loaded and after that the loading icon will be displayed, which is not what we want. We want that both the functions should work at the same time. Here threads come to rescue. We can create two threads and then call the two functions, one on each thread and acheive our desired goal.
But while using threads, we need to take care of the synchronization issues as well. We need to ensure that two threads should not modify the same resource at the same time.