Running a process in background/foreground in linux

Run process in background
To run a command in background, you can use following command at command prompt

$ command &

Above command will make your process run in background. You need to make sure that process is finished before logging off. A process run by above command will be terminated as soon as you logout.
If you want to run a command in background even after you logout then you can use following command

$ nohup command &

nohup Run a command immune to hang ups, with output to a non-tty.
This command will run your process in background even if you logs out.

Making current process to run in background
You can make current process as a background process by issuing following commands.

$ [ctrl] + z
$ bg

You need to remember that the process is running in background, if you logs out then process will be terminated. You can disown to avoid killing the process after you close the terminal.

$ [ctrl] + z
$ bg
$ disown

Execute following command to run any process in background

$ bg process_id

You can find process id by issues ps command. It displays the list of currently running process and their process ids. Use ps aux to see all the process currently running on your system including from other users. Use top to get updated list of all the processes running currently.

Run a process in foreground

$ fg process_id

java.util.regex.PatternSyntaxException: Unclosed character class

Exception in thread "main" java.util.regex.PatternSyntaxException:
Unclosed character class near index 1 $[ ^ at java.util.regex.Pattern.error (Pattern.java:1503) at
java.util.regex.Pattern.clazz(Pattern.java:2016) at java.util.regex.Pattern.sequence(Pattern.java:1560)
at java.util.regex.Pattern.expr(Pattern.java:1520) at java.util.regex.Pattern.compile (Pattern.java:1288)
at java.util.regex.Pattern.<init>(Pattern.java:1044)  encountered while splitting the string
using a delimiter which contains "["

NoClassDefFoundError: com/lowagie/text/DocumentException

I am get following exception.

Exception in thread "main" java.lang.NoClassDefFoundError: com/lowagie/text/DocumentException at net.sf.jasperreports.engine.JasperExportManager.exportReportToPdf(JasperExportManager.java:183) at net.sf.jasperreports.engine.JasperRunManager.runReportToPdf(JasperRunManager.java:305)  at Report.main(Report.java:45)

Help me asap.

JSON communication between server and client Part1

JSON (JavaScript Object Notation) provides lightweight data exchange between server and client. It is human readable.
Sending data in JSON format from server to client:
There are APIs present for many languages (Java, ASP, Flex, C, C++ etc). With the help of these APIs, we can get JSON representation for data or objects. This data can be send to client just like some other data.
On the client side browser can handle this format and one can retrieve the information send from server.
I am writing code sample for spring framework

public void getJSONInfo(HttpServletRequest request, HttpServletResponse response) throws Exception {
    JSONObject result = new JSONObject();
    try {
        Object obj = new Object();
        // To get JSON data from obj
       JSONObject jsonObj = JSONObject.fromObject(obj);
       result.put("result", "success");
       result.put("jsonInfo", jsonObj);
   } catch (Exception e) {
       result.put("result", "error");
  } finally {
      // Write this jsonObj in HttpServletResponse
      response.getWriter().print(result);
      response.flushBuffer();
   }
}

While on the client side, I am using jquery to make AJAX request,

function getJSONInfo() {
    $.ajax({
       url: '../location?q=getJSONInfo',
       type: "POST",
       cache: false,
       dataType: "json",
       success: function(response){
           alert(response.jsonInfo);
       },
       error: function(msg){
       }
    });
}

As we can see from the example, an ajax request is made to get JSONInfo and result is displayed in popup window.

Sending data in JSON format from client to server will be covered in part2

java.util.ConCurrentModificationException

I tried to execute following code

ListIterator iterator = i.listIterator();
while(iterator.hasNext()) {
      System.out.println(iterator.next());
      Object obj=((Integer)iterator.next()).intValue();
      if(obj.equals(i.get(1))) {
           i.add(10);
      }
}

ant it throws following exception

Exception in thread "main" java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
at java.util.AbstractList$Itr.next(AbstractList.java:343)

More than one value of type [net.sf.jasperreports.engine.JRDataSource] found

I getting this exception while using a subreport in my jasper report and trying to pass a datasource for my subreport. Datasource for report is ‘datasource’ and datasource for subreport is ‘pardatasource’.

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: More than one value of type [net.sf.jasperreports.engine.JRDataSource] found
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:488)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:431)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:265)
org.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:107)
org.acegisecurity.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:72)
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:110)
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
com.ccclogic.core.filter.SessionTimeoutFilter.doFilter(SessionTimeoutFilter.java:127)

rpm command – can’t create transaction lock

In case if you are getting error on running rpm command e.g.

$ rpm -e jdk-wrapper-1.5.0_15-1.gdg.noarch
error: can't create transaction lock on /var/lib/rpm/__db.000

javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS

I am getting exception while sending mail using JavaMail APIs. Mail properties are as

	mail.transport.protocol = smtp
	mail.smtp.host = mailHost
	mail.smtp.port = 25
	mail.smtp.auth = true

The exception I am getting while sending email

Exception in thread "main" javax.mail.SendFailedException: Sending failed;
        nested exception is:
	javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command first m1sm949464nzf
 	at javax.mail.Transport.send0(Transport.java:219)
	at javax.mail.Transport.send(Transport.java:81)
	at example.SendMailUsingAuthentication.postMail(SendMailUsingAuthentication.java:77)
	at example.SendMailUsingAuthentication.main(SendMailUsingAuthentication.java:35)

Error in setting up Quartz (Spring framework)

'org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.scheduling.quartz.SchedulerFactoryBean' defined in ServletContext resource [/WEB-INF/tvp-job.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/transaction/UserTransaction
Caused by:
java.lang.NoClassDefFoundError: javax/transaction/UserTransaction
	at org.quartz.impl.StdSchedulerFactory.instantiate(StdSchedulerFactory.java:1104)
	at org.quartz.impl.StdSchedulerFactory.getScheduler(StdSchedulerFactory.java:1355)
	at org.springframework.scheduling.quartz.SchedulerFactoryBean.createScheduler(SchedulerFactoryBean.java:687)
	at org.springframework.scheduling.quartz.SchedulerFactoryBean.afterPropertiesSet(SchedulerFactoryBean.java:582)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1203)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1172)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:427)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)

java.sql.SQLException: Closed Connection

Caused by: java.sql.SQLException: Closed Connection: next at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:185) at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForList(GeneralStatement.java:123)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:610)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:584)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:101)
at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList(SqlMapClientImpl.java:78)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)

Next Page →

Technology