Posts

How to read properties file using ANT

Suppose You have to access some properties (from a file), which are already defined in my build file. To be able to access the properties We can use the build attribute of the property task.  build.properties #Release information #Thu Oct 14 16:25:12 CEST 2004 build.number=115 release.version=0.4 release.name=framework   Ant Example Target <target name="read.properties"> <!-- Read the properties from the release of the framework --> <property file="build.properties" prefix="build"/> <echo message="${build.build.number}"/> <echo message="${build.release.version}"/> <echo message="${build.release.name}"/> </target>    Output Buildfile: C:\build.xml read.properties: [echo] 115 [echo] 0.4 [echo] framework BUILD SUCCESSFUL Total time: 3 seconds

chkconfig Command Examples

chkconfig command is used to setup, view, or change services that are configured to start automatically during the system startup. chkconfig has five distinct functions: adding new services for management, removing services from management, listing the current startup information for services, changing the startup information for services, and checking the startup state of a particular service. chkconfig --list [ name ] chkconfig --add name chkconfig --del name chkconfig [ --level levels ] name < on | off | reset > chkconfig [ --level levels ] name   OPTIONS --level levels Specifies the run levels an operation should pertain to. It is given as a string of numbers from 0 to 7. For example, --level 35 specifies runlevels 3 and 5. --add name This option adds a new service for management by chkconfig . --del name The service is removed from chkconfig management. --list name This option lists all of the services which chkconfig...

Embedding Jetty Tutorial

Jetty : Jetty is an open source servlet container, which means it serves Java-based web content such as servlets and JSPs. Jetty is written in Java and its API is available as a set of JARs. Developers can instantiate a Jetty container as an object, instantly adding network and web connectivity to a stand-alone Java app. Jetty has a slogan, "Don't deploy your application in Jetty, deploy Jetty in your application." What this means is that as an alternative to bundling your application as a standard WAR to be deployed in Jetty, Jetty is designed to be a software component that can be instantiated and used in a Java program just like any POJO . Put another way, running Jetty in embedded mode means putting an HTTP module into your application, rather than putting your application into an HTTP server.  To embed a Jetty server, the following steps are typical: Create the server Add/Configure Connectors Add/Configure Handlers Add/Configure...

How to find default thread pool size programmatically

To find out jetty thread pool size programmatically : ThreadPool tp = (ThreadPool) server.getThreadPool(); if(tp instanceof QueuedThreadPool) { QueuedThreadPool qtp = (QueuedThreadPool) tp; int minThreads = qtp.getMinThreads(); int maxThreads = qtp.getMaxThreads(); LOG.info("minThreads : " + minThreads + "\t maxThreads :" + maxThreads) }

How to get RAM size using java?

package com.demo.memoryheap; import java.lang.management.ManagementFactory; /**  * @author abdul  *  */ public class FreeMemoryUsingMxBean {     /**      * @param args      */     public static void main(String[] args) {         com.sun.management.OperatingSystemMXBean mxbean = (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();                 System.out.println("Total Memory in MB: " + mxbean.getTotalPhysicalMemorySize()/(1024*1024));                 System.out.println("Free Memory in MB: " + mxbean.getFreePhysicalMemorySize()/(1024*1024));     } } Note : If you get access restriction error while working on Eclipse , check this : Access Restriction issue

Access restriction on class due to restriction on required library rt.jar for OperatingSystemMXBean ?

Its work for me : Go to the Build Path settings in the project properties. Remove the JRE System Library Add it back; Select "Add Library" and select the JRE System Library. The default worked for me

How to convert InputStream to String in Java?

/**  *  */ package convert.stream.to.string; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; /**  * @author abdul  *  */ public class StreamToString {     /**      * @param args      */     public static void main(String[] args) {         StreamToString streamToString = new StreamToString();               //intilize an InputStream         InputStream is = new ByteArrayInputStream("file content:\nData1\nData2".getBytes());               /*          * Call the method to convert the stream to string          */  ...