java.lang.OutOfMemoryError: PermGen space in Stanbol

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.1:compile (default-compile) on project org.apache.stanbol.commons.solr.web: Compilation failure
[ERROR] Failure executing javac, but could not parse the error:
[ERROR]
[ERROR]
[ERROR] The system is out of resources.
[ERROR] Consult the following stack trace for details.
[ERROR] java.lang.OutOfMemoryError: PermGen space
[ERROR] at java.lang.ClassLoader.defineClass1(Native Method)
[ERROR] at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
[ERROR] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[ERROR] at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
[ERROR] at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
[ERROR] at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
[ERROR] at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
[ERROR] at java.security.AccessController.doPrivileged(Native Method)
[ERROR] at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
[ERROR] at org.codehaus.plexus.compiler.javac.IsolatedClassLoader.loadClass(IsolatedClassLoader.java:56)
[ERROR] at com.sun.tools.javac.main.Main.compile(Main.java:424)
[ERROR] at com.sun.tools.javac.main.Main.compile(Main.java:353)
[ERROR] at com.sun.tools.javac.main.Main.compile(Main.java:342)
[ERROR] at com.sun.tools.javac.main.Main.compile(Main.java:333)
[ERROR] at com.sun.tools.javac.Main.compile(Main.java:94)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
[ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR] at java.lang.reflect.Method.invoke(Method.java:606)
[ERROR] at org.codehaus.plexus.compiler.javac.JavacCompiler.compileInProcess(JavacCompiler.java:549)
[ERROR] at org.codehaus.plexus.compiler.javac.JavacCompiler.compile(JavacCompiler.java:156)
[ERROR] at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:605)
[ERROR] at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:128)
[ERROR] at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)

The solution is,

This error is happening because the JVM parameters for the BigDataLite NoSQL has been not set properly. So you need to add the JVM memory paremeters in ~/.bashrc file. follow the steps,
sudo nano ~/.bashrc
Add the below line in to this file,
export JAVA_OPTS="-Xms128m -Xmx2048m -XX:PermSize=256m -XX:MaxPermSize=2048m"
Finally refresh the ~/.bashrc with the below command,
source ~/.bashrc
Now execute it again.

Best Eclipse plugin

http://www.eclipse.org/Xtext/index.html for any script or build language. This eclispe plugin helps lot.

Why use getters and setters?

  • Encapsulation of behavior associated with getting or setting the property - this allows additional functionality (like validation) to be added more easily later.
  • Hiding the internal representation of the property while exposing a property using an alternative representation.
  • Insulating your public interface from change - allowing the public interface to remain constant while the implementation changes without affecting existing consumers.
  • Controlling the lifetime and memory management (disposal) semantics of the property - particularly important in non-managed memory environments (like C++ or Objective-C).
  • Providing a debugging interception point for when a property changes at runtime - debugging when and where a property changed to a particular value can be quite difficult without this in some languages.
  • Improved interoperability with libraries that are designed to operate against property getter/setters - Mocking, Serialization, and WPF come to mind.
  • Allowing inheritors to change the semantics of how the property behaves and is exposed by overriding the getter/setter methods.
  • Allowing the getter/setter to be passed around as lambda expressions rather than values.
  • Getters and setters can allow different access levels - for example the get may be public, but the set could be protected.
For example, if foo was public, I could easily set it to null and then someone else could try to call a method on the object. But it's not there anymore! With a setFoo method, I could ensure that foo was never set to null.

Accessors and mutators also allow for encapsulation - if you aren't supposed to see the value once its set (perhaps it's set in the constructor and then used by methods, but never supposed to be changed), it will never been seen by anyone. But if you can allow other classes to see or change it, you can provide the proper accessor and/or mutator.

Download Stanford CoreNLP models using Maven

 <dependencies>  
 <dependency>  
   <groupId>edu.stanford.nlp</groupId>  
   <artifactId>stanford-corenlp</artifactId>  
   <version>3.2.0</version>  
 </dependency>  
 <dependency>  
   <groupId>edu.stanford.nlp</groupId>  
   <artifactId>stanford-corenlp</artifactId>  
   <version>3.2.0</version>  
   <classifier>models</classifier>  
 </dependency>  
 </dependencies>

How to generate UML Diagrams from Java code in Eclipse

UML diagrams compliment inline documentation ( javadoc ) and allow to better explore / understand a design. Moreover, you can print and bring them to table to discuss a design.

In this post, we will install and use the ObjectAid plugin for Eclipse to produce jUnit lib class diagrams. Then, we will be able to generate UML diagrams by simply dragging and dropping classes into the editor. We can further manipulate the diagram by selecting which references, operations or attributes to display.

Open Eclipse and go to Help > Install New Software
Click on add to add a new repository
Enter name ObjectAid UML Explorer
Enter Location http://www.objectaid.net/update

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 :