Maven Installation

 Search Maven package  
 apt-cache search maven  

 Install it  
 sudo apt-get install maven  

 Verification  
 mvn -version  

 Where is Maven installed  
 The command apt-get install the Maven in /usr/share/maven  
 The Maven configuration files are stored in /etc/maven  

Installation of Tomcat7 : using port 80

 Installation Tomcat using apt-get  
 sudo apt-get install tomcat7  

 Install the package using apt-get  
 sudo apt-get install tomcat7-docs  
 sudo apt-get install tomcat7-examples  
 sudo apt-get install tomcat7-admin  

 The above instruction is more than enough to install the tomcat. If any error happened please follow the below the instructions.  
 Setup the JDK path for Tomcat   
 sudo nano /etc/default/tomcat7 : add the JDK path inside the file  
 Set the path   
 sudo nano ~/.bashrc  
 export CATALINA_HOME=/usr/share/tomcat7  

 Stop Server:  
 sudo /etc/init.d/tomcat7 stop  

 Start Server:  
 sudo /etc/init.d/tomcat7 start  

 Folder locations of tomcat :  
 Tomcat bin and lib file location :  
 /usr/share/tomcat7  

 Tomcat xml file :  
 /etc/tomcat7  

 Tomcat config and webapp files:  
 /var/lib/tomcat7/  

 Tomcat JDK and Path Setup   
 sudo nano /etc/default/tomcat7  

 To Run Tomcat on port 80  
 <Connector port="8080" protocol="HTTP/1.1"  
 connectionTimeout="20000" redirectPort=  
 "8443" />  
 Change 8080 to 80 in /config/server.xml file  
  AND  

 Remove the comment using :  
 sudo nano /etc/default/tomcat7 and   
 change #AUTHBIND=no  
 as AUTHBIND=yes  

 To remove all the files   
 sudo apt-get purge libtomcat7-java tomcat6 tomcat6-admin tomcat6-docs tomcat6-examples tomcat7 tomcat7-admin tomcat7-common tomcat7-docs tomcat7-examples tomcat7-user  
 To check what are the process running on port 80  
 netstat -tulpn | grep :80  
 Server.XML user name and password  
 <role rolename="manager-gui"/>  
 <user username="Dhanu" password="" roles="manager-gui"/>  
 <role rolename="admin-gui"/>  
 <user username="Dhanu" password="" roles="admin-gui"/> 
 
 NOTE:  
 Change the Heap memory in tomcat :  
 sudo nano /etc/default/tomcat7 and change the line on -Xms value  
 JAVA_OPTS="-Djava.awt.headless=true -Xmx2048m -XX:+UseConcMarkSweepGC"  
 In Default It’s limited to 128MB.   

Difference between Process and Thread

Process

  • An executing instance of a program is called a process.
  • Some operating systems use the term ‘task‘ to refer to a program that is being executed.
  • A process is always stored in the main memory also termed as the primary memory or random access memory.
  • Therefore, a process is termed as an active entity. It disappears if the machine is rebooted.
  • Several process may be associated with a same program.
  • On a multiprocessor system, multiple processes can be executed in parallel.
  • On a uni-processor system, though true parallelism is not achieved, a process scheduling algorithm is applied and the processor is scheduled to execute each process one at a time yielding an illusion of concurrency.
  • Example: Executing multiple instances of the ‘Calculator’ program. Each of the instances are termed as a process.

Thread

  • A thread is a subset of the process.
  • It is termed as a ‘lightweight process’, since it is similar to a real process but executes within the context of a process and shares the same resources allotted to the process by the kernel (See kquest.co.cc/2010/03/operating-system for more info on the term ‘kernel’).
  • Usually, a process has only one thread of control – one set of machine instructions executing at a time.
  • A process may also be made up of multiple threads of execution that execute instructions concurrently.
  • Multiple threads of control can exploit the true parallelism possible on multiprocessor systems.
  • On a uni-processor system, a thread scheduling algorithm is applied and the processor is scheduled to run each thread one at a time.
  • All the threads running within a process share the same address space, file descriptor, stack and other process related attributes.
  • Since the threads of a process share the same memory, synchronizing the access to the shared data withing the process gains unprecedented importance.

What is Java thread


A thread is a thread of execution in a program. The Java Virtual Machine allows an application to have multiple threads of execution running concurrently.

Every thread has a priority. Threads with higher priority are executed in preference to threads with lower priority. Each thread may or may not also be marked as a daemon. When code running in some thread creates a new Thread object, the new thread has its priority initially set equal to the priority of the creating thread, and is a daemon thread if and only if the creating thread is a daemon.

Difference between “implements Runnable” and “extends Thread” in java

In java language, as we all know that there are two ways to create threads. One using Runnable interface and another by extending Thread class.

There has been a good amount of debate on which is better way. Well, I also tried to find out and below is my learning:

1) Implementing Runnable is the preferred way to do it. Here, you’re not really specializing or modifying the thread’s behavior. You’re just giving the thread something to run. That means composition is the better way to go.

2) Java only supports single inheritance, so you can only extend one class.

3) Instantiating an interface gives a cleaner separation between your code and the implementation of threads.

4) Implementing Runnable makes your class more flexible. If you extend thread then the action you’re doing is always going to be in a thread. However, if you extend Runnable it doesn’t have to be. You can run it in a thread, or pass it to some kind of executor service, or just pass it around as a task within a single threaded application.

5) By extending Thread, each of your threads has a unique object associated with it, whereas implementing Runnable, many threads can share the same runnable instance.

6) If you are working on JDK 4 or lesser, then there is bug :