| 12:57 PM | |
| http://angular-ui.github.io/ui-calendar/ http://fullcalendar.io/ |
Benny Java
Tuesday, June 28, 2016
Wednesday, February 6, 2013
Overcome Unsuported Lunch types in Eclipse
Got stuck on this for a while and finally got it fixed. So decided to post it in the blog.
Locate the files under workspace\.metadata\.plugins\org.eclipse.debug.core\.launches
Remove the Project File that is complaining about the unsupported Launch Type.
Tuesday, December 18, 2012
Mod_rewrite proxy redirect on HTTP_METHODs
Use the REQUEST_METHOD environment variable in apache conf to accomplish this.
Add a condition for the HTTP METHOD.
ReWriteEngine on
RewriteCond %{REQUEST_METHOD} ^GET
RewriteRule ^/ef/bsslp/associations/party?(.*) http://hostA:9080/ef/efbslp/services/rest/viewBsslpPartyAssociation?$1 [P]
RewriteCond %{REQUEST_METHOD} ^POST
RewriteRule ^/ef/bsslp/associations/party$ http://hostA:9080/ef/efbslp/services/rest/addBsslpPartyAssociation [P]
RewriteCond %{REQUEST_METHOD} ^PUT
RewriteRule ^/ef/bsslp/associations/party$ http://hostA:9080/ef/efbslp/services/rest/updateBsslpPartyAssociation [P]
Add a condition for the HTTP METHOD.
ReWriteEngine on
RewriteCond %{REQUEST_METHOD} ^GET
RewriteRule ^/ef/bsslp/associations/party?(.*) http://hostA:9080/ef/efbslp/services/rest/viewBsslpPartyAssociation?$1 [P]
RewriteCond %{REQUEST_METHOD} ^POST
RewriteRule ^/ef/bsslp/associations/party$ http://hostA:9080/ef/efbslp/services/rest/addBsslpPartyAssociation [P]
RewriteCond %{REQUEST_METHOD} ^PUT
RewriteRule ^/ef/bsslp/associations/party$ http://hostA:9080/ef/efbslp/services/rest/updateBsslpPartyAssociation [P]
Monday, November 12, 2012
Running long running JSP using a thread implementation
This works well in a proxy-ed environment with a session affinity to a JVM from the webtier.
Steps involve creating a worker thread which executes the long running process activity. Create a mechanism to look back on the process at regular intervals from the browser for completion. If the process did not complete kill the thread and report back as "timed out". If there are orphaned process kill them with the help of a maintenance thread initiated by a startup servlet.
Here is the example code samples.
class WorkingThread extends Thread implements Runnable {
String sessionId;
public WorkingThread () {
}
public WorkingThread (String sessionId) {
this.sessionId = sessionId;
}
public void run() {
System.out.println(" Working thread");
try {
synchronized (TestServletWorker.workerMap) {
HashMap
threadDetails.put("time", new Long( System.currentTimeMillis()));
}
Thread.sleep(1000 * 60 * 3); // implement the business logic
synchronized (TestServletWorker.workerMap) {
HashMap
threadDetails.put("Data", "my Data --> Done");
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void stopThisThread () {
// Stop application functions here
this.interrupt();
try {
this.join ();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Create Environment variables in WebSphere 6
Define your websphere variable someVariable = someValue
Go to (something like) Servers -> Server Types -> Websphere application servers -> YOUR_SERVER -> Java and process management -> Process definition -> Java virtual machine -> Custmo properties
Define a new variable someVariable = ${someVariable}
Wednesday, February 15, 2012
Running long running JSP using a thread implementation
This works well in a proxy-ed environment with a session affinity to a JVM from the webtier.
Steps involve creating a worker thread which executes the long running process activity. Create a mechanism to look back on the process at regular intervals from the browser for completion. If the process did not complete kill the thread and report back as "timed out". If there are orphaned process kill them with the help of a maintenance thread initiated by a startup servlet.
Here is the example code samples.
class WorkingThread extends Thread implements Runnable {
String sessionId;
public WorkingThread () {
}
public WorkingThread (String sessionId) {
this.sessionId = sessionId;
}
public void run() {
System.out.println(" Working thread");
try {
synchronized (TestServletWorker.workerMap) {
HashMap threadDetails = (HashMap) TestServletWorker.workerMap.get(sessionId);
threadDetails.put("time", new Long( System.currentTimeMillis()));
}
Thread.sleep(1000 * 60 * 3); // implement the business logic
synchronized (TestServletWorker.workerMap) {
HashMap threadDetails = (HashMap) TestServletWorker.workerMap.get(sessionId);
threadDetails.put("Data", "my Data --> Done");
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void stopThisThread () {
// Stop application functions here
this.interrupt();
try {
this.join ();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Method to call initiate/track/check/retrieve the Application data from a JSP or any action classes.
public class TestServletWorker {
public static HashMap workerMap;
static {
System.out.println("testServletWorker");
workerMap = new HashMap ();
}
public static synchronized String testServletWorkerrunner (String sessionId) {
if (workerMap != null && workerMap.containsKey(sessionId) ) {
HashMap wtHash = (HashMap) workerMap.get(sessionId);
WorkingThread wt = (WorkingThread) wtHash.get("thread");
if ( !wt.isAlive() ) {
System.out.println("not alive ");
String ret = (String) wtHash.get("Data");
workerMap.remove(sessionId);
return ret;
} else if ( wt.isInterrupted() ) {
wtHash.put("Data", "timed out");
workerMap.remove(sessionId);
return "timed out";
}
} else if (workerMap != null && !workerMap.containsKey(sessionId)) {
WorkingThread wt = new WorkingThread (sessionId);
wt.start();
HashMap threadDetails = new HashMap ();
threadDetails.put("thread", wt);
workerMap.put(sessionId, threadDetails);
}
return null;
}
}
Thread to stop any abandoned or orphan threads
public class StopThreadServlet extends HttpServlet implements Servlet {
/**
*
*/
private static final long serialVersionUID = 1L;
public void init() throws ServletException {
System.out.println(": Registering .... ");
threadKiller tk = new threadKiller ();
tk.start();
while ( true ) {
try {
if ( !tk.isAlive() ) {
tk.start();
}
} catch (Exception w) {
w.printStackTrace();
}
}
}
}
class threadKiller extends Thread {
public void run () {
while ( true ) {
try {
Thread.sleep(1000 * 30 * 1); // Run every 1/2 minutes
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
synchronized ( TestServletWorker.workerMap) {
System.out.println( TestServletWorker.workerMap.size() + " current size");
if ( TestServletWorker.workerMap != null && TestServletWorker.workerMap.size() > 0) {
Set s = TestServletWorker.workerMap.keySet();
Iterator it = s.iterator();
while ( it.hasNext()) {
String sessionId = (String) it.next();
System.out.println(sessionId );
HashMap threadDetails = (HashMap)TestServletWorker.workerMap.get(sessionId);
long starttime = ((Long) threadDetails.get("time")).longValue();
long currtime = System.currentTimeMillis();
long diffIntime = currtime - starttime;
if ( diffIntime > 1000 * 60 * 2 ) { // Kill threads > 2 minutes
System.out.println("stop this thread > 2 mins");
WorkingThread thrd = (WorkingThread) threadDetails.get("thread"); // Replace with WorkerThread impl class
threadDetails.put("Data", "timed out");
thrd.stopThisThread(); // Call a stop function in the the Thread implementation class.
System.out.println( TestServletWorker.workerMap.size() + " New current size");
}
}
}
}
}
}
}
Start up servlet configuration in web.xml
<servlet>
<description>Stopthreads running for long duration</description>
<display-name>Stopthreads</display-name>
<servlet-name>Stopthreads</servlet-name>
<servlet-class>StopThreadServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
Steps involve creating a worker thread which executes the long running process activity. Create a mechanism to look back on the process at regular intervals from the browser for completion. If the process did not complete kill the thread and report back as "timed out". If there are orphaned process kill them with the help of a maintenance thread initiated by a startup servlet.
Here is the example code samples.
class WorkingThread extends Thread implements Runnable {
String sessionId;
public WorkingThread () {
}
public WorkingThread (String sessionId) {
this.sessionId = sessionId;
}
public void run() {
System.out.println(" Working thread");
try {
synchronized (TestServletWorker.workerMap) {
HashMap
threadDetails.put("time", new Long( System.currentTimeMillis()));
}
Thread.sleep(1000 * 60 * 3); // implement the business logic
synchronized (TestServletWorker.workerMap) {
HashMap
threadDetails.put("Data", "my Data --> Done");
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void stopThisThread () {
// Stop application functions here
this.interrupt();
try {
this.join ();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Method to call initiate/track/check/retrieve the Application data from a JSP or any action classes.
public class TestServletWorker {
public static HashMap
static {
System.out.println("testServletWorker");
workerMap = new HashMap
}
public static synchronized String testServletWorkerrunner (String sessionId) {
if (workerMap != null && workerMap.containsKey(sessionId) ) {
HashMap
WorkingThread wt = (WorkingThread) wtHash.get("thread");
if ( !wt.isAlive() ) {
System.out.println("not alive ");
String ret = (String) wtHash.get("Data");
workerMap.remove(sessionId);
return ret;
} else if ( wt.isInterrupted() ) {
wtHash.put("Data", "timed out");
workerMap.remove(sessionId);
return "timed out";
}
} else if (workerMap != null && !workerMap.containsKey(sessionId)) {
WorkingThread wt = new WorkingThread (sessionId);
wt.start();
HashMap
threadDetails.put("thread", wt);
workerMap.put(sessionId, threadDetails);
}
return null;
}
}
Thread to stop any abandoned or orphan threads
public class StopThreadServlet extends HttpServlet implements Servlet {
/**
*
*/
private static final long serialVersionUID = 1L;
public void init() throws ServletException {
System.out.println(": Registering .... ");
threadKiller tk = new threadKiller ();
tk.start();
while ( true ) {
try {
if ( !tk.isAlive() ) {
tk.start();
}
} catch (Exception w) {
w.printStackTrace();
}
}
}
}
class threadKiller extends Thread {
public void run () {
while ( true ) {
try {
Thread.sleep(1000 * 30 * 1); // Run every 1/2 minutes
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
synchronized ( TestServletWorker.workerMap) {
System.out.println( TestServletWorker.workerMap.size() + " current size");
if ( TestServletWorker.workerMap != null && TestServletWorker.workerMap.size() > 0) {
Set
Iterator
while ( it.hasNext()) {
String sessionId = (String) it.next();
System.out.println(sessionId );
HashMap
long starttime = ((Long) threadDetails.get("time")).longValue();
long currtime = System.currentTimeMillis();
long diffIntime = currtime - starttime;
if ( diffIntime > 1000 * 60 * 2 ) { // Kill threads > 2 minutes
System.out.println("stop this thread > 2 mins");
WorkingThread thrd = (WorkingThread) threadDetails.get("thread"); // Replace with WorkerThread impl class
threadDetails.put("Data", "timed out");
thrd.stopThisThread(); // Call a stop function in the the Thread implementation class.
System.out.println( TestServletWorker.workerMap.size() + " New current size");
}
}
}
}
}
}
}
Start up servlet configuration in web.xml
<servlet>
<description>Stopthreads running for long duration</description>
<display-name>Stopthreads</display-name>
<servlet-name>Stopthreads</servlet-name>
<servlet-class>StopThreadServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
Thursday, February 9, 2012
OSGI best practices IBM link
http://www.ibm.com/developerworks/websphere/techjournal/1007_charters/1007_charters.html
Subscribe to:
Comments (Atom)