Manish Malhotra

Greenhorn
+ Follow
since Apr 05, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Manish Malhotra

"""" Always a tough question. Where do exceptions finally land? One approach I've seen is to have a Business Delegate on the client-side capture the RemoteException and then translate the exception in to something more meaningful, say a custom exception that could be displayed to the user in a meaningful form. (see J2EE Patterns Catalog: www.java.sun.com/blueprints/corej2eepatterns/Patterns/index.html)
So in your example, catch the SQLException, use the SQLException to create and throw a new EJBException, then catch it in your Business Delegate on the client side. At that point translate it in to some kind of custom exception that is displayable to the user.
Overall, I like using a Business Delegate to sheild the client from communication concerns and even from the fact that EJBs are being used! Hope this helps. """"""""
You said is quite correct but my problem is that if I throw EJBException when SQLExc. occured then could I get the errorCode from the EJBException object to identify the SQL error occured to show the pick a proper error message from the property file.
And my stateless session bean is Bean Managed therefore DB transaction stuff Im handling in the bean methods itself and dependent on the Container so that it will make rollback or commit when container get any System Level Exception.
Please reply as soon as possible.
Im waiting right now on net.
Manish
Hi,
Im having on session bean, or any other EJB's & if any of its method will throw the SQLException or any checked exception.
And Im calling this bean from the same container then its giving me proper exception say if any db error occurs then giving the SQLExc...
But I want to know that if I'll a client which is on some other machine then will it be able to get the SQLException or other system level exception or it will get only RemoteException..
Please, help as quick as possible.
Im looking for the solution.
regards& thanks,
Manish
SE.
PCS.
OPTION I: client calls stub - stub does marshalling & contacts skeleton - skeleton does unmarshalling & contacts EJBObject to get an instance of the bean - EJBObject contacts business methods & response comes back thru' the same process.
======================
General -->> When you call create method on Home then your home create or get the instance of your bean from the pool, and then it associates the EJBObject's object with your bean instance & EJBObject impelements the remote interface.
The concept of stub is correct as per my knowledge what you are thinking. But I think now there is no skeleton on the server side.

OPTION II: client calls an interface that implements EJBlocalHome --which further contacts an interface that implements EJBlocalObject - which creates an instance of the bean and contacts the bean to run the logic.
=====
I dont know much about the local interface concept in EJB2.0
regards,
Manish Malhotra
SE, PCS. IND
By default there wouldnt be any transaction attr. for any method & no need to give tr. att. for the call back methods.
And I dnt think so that you need to give tr. attr. for your Session Facade bean as already from this you are calling the entity bean which you would be having tra. attr.
so, no need to worry abt the callback methods..
regards,
Manish Malhotra
SE. PCS. IND.
Hi All,
This is my code.
private static final String PROVIDER_URL = "corbaloc:iiop:localhost:2809";
private static final String INITIAL_CONTEXT_FACTORY = "com.ibm.websphere.naming.WsnInitialContextFactory";
Hashtable htAppProperties = new Hashtable(2);
htAppProperties.put(Context.PROVIDER_URL, PROVIDER_URL);
htAppProperties.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
System.out.println("Looking up : " + PROVIDER_URL + " : " + INITIAL_CONTEXT_FACTORY);
Context lookupContext = new InitialContext(htAppProperties);
Object obj = lookupContext.lookup("jms/gvstopic");
System.out.println("Lookup is successful : " + obj);
Object objFac = lookupContext.lookup("jms/gvstopicfactory");
System.out.println("Lookup is successful new : " + objFac);
System.out.println("--------------------------------");
System.out.println("Topic is : " + (Topic)obj);
System.out.println("TopicConnectionFactory is : " +(TopicConnectionFactory)objFac);
-------------------------------
Im running this code on WSAD. The JMS factory & topic is already added at (wesphere5.00)test environment of WSAD.
But its giving this exception..
...
javax.naming.ConfigurationException: Malformed provider URL: corbaloc:iiop:localhost:2809/NameServiceServerRoot
at com.ibm.ws.naming.util.WsnInitCtxFactory.parseBootstrapURL(WsnInitCtxFactory.java:1422)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getInitialContextInternal(WsnInitCtxFactory.java:368)
at com.ibm.ws.naming.util.WsnInitCtx.getContext(WsnInitCtx.java:102)
at com.ibm.ws.naming.util.WsnInitCtx.getContextIfNull(WsnInitCtx.java:408)
at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:131)
at javax.naming.InitialContext.lookup(InitialContext.java:359)
at TestConfig.publishRefreshCache(TestConfig.java:116)
at TestConfig.main(TestConfig.java:56)
----------------------
And if Im running this code from ouside the WSAD envrionment and on the WSAD server itself is running fine.
Please , help me Im running out of time.
Thanks in advance.
regards,
Manish Malhotra
Can anybody please help me to figure out the response time calculation in the Web Application.
Actually my task is to calculate the response time for certain period of time
one is longer period
second is smaller period
then compare the average of both to get the idea about the system health.
please reply asap!.
thanks & regards
manish malhotra
20 years ago
Can anybody please help me to figure out the response time calculation in the Web Application.
Actually my task is to calculate the response time for certain period of time
one is longer period
second is smaller period
then compare the average of both to get the idea about the system health.
please reply asap!.
thanks & regards
manish malhotra
20 years ago
What is/are the system calls that I need to use to identify what the CPU and RAM usage percentage.
I want to use C code to get the System Usage in linux OSplateform.
And finnaly use jni concept to call the C function and get the Sys. usage info.
Act. I downloaded code for this from a site but its for win32 plateform. And the C file is giving error, I think some system call are plateform specific & that is giving problem like.
1. GetCurrentProcess ()
2. GetProcessTimes(
etc.
==========================
here is the C code.
/* ------------------------------------------------------------------------- */
/*
* An implementation of JNI methods in com.vladium.utils.SystemInformation
* class. The author compiled it using Microsoft Visual C++ but the code
* should be easy to use with any compiler for win32 platform.
*
* For simplicity, this implementaion assumes JNI 1.2+ and omits error handling.
*
* (C) 2002, Vladimir Roubtsov [vlad@trilogy.com]
*/
/* ------------------------------------------------------------------------- */
#include <windows.h>
#include <process.h>
#include <winbase.h>
#include "com_vladium_utils_SystemInformation.h"
static jint s_PID;
static HANDLE s_currentProcess;
static int s_numberOfProcessors;
/* ------------------------------------------------------------------------- */
/*
* A helper function for converting FILETIME to a LONGLONG [safe from memory
* alignment point of view].
*/
static LONGLONG
fileTimeToInt64 (const FILETIME * time)
{
ULARGE_INTEGER _time;
_time.LowPart = time->dwLowDateTime;
_time.HighPart = time->dwHighDateTime;
return _time.QuadPart;
}
/* ......................................................................... */
/*
* This method was added in JNI 1.2. It is executed once before any other
* methods are called and is ostensibly for negotiating JNI spec versions, but
* can also be conveniently used for initializing variables that will not
* change throughout the lifetime of this process.
*/
JNIEXPORT jint JNICALL
JNI_OnLoad (JavaVM * vm, void * reserved)
{
SYSTEM_INFO systemInfo;

s_PID = _getpid ();
s_currentProcess = GetCurrentProcess ();
GetSystemInfo (& systemInfo);
s_numberOfProcessors = systemInfo.dwNumberOfProcessors;
return JNI_VERSION_1_2;
}
/* ......................................................................... */
/*
* Class: com_vladium_utils_SystemInformation
* Method: getProcessID
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_com_vladium_utils_SystemInformation_getProcessID (JNIEnv * env, jclass cls)
{
return s_PID;
}
/* ......................................................................... */
/*
* Class: com_vladium_utils_SystemInformation
* Method: getProcessCPUTime
* Signature: ()J
*/
JNIEXPORT jlong JNICALL
Java_com_vladium_utils_SystemInformation_getProcessCPUTime (JNIEnv * env, jclass cls)
{
FILETIME creationTime, exitTime, kernelTime, userTime;

GetProcessTimes (s_currentProcess, & creationTime, & exitTime, & kernelTime, & userTime);
return (jlong) ((fileTimeToInt64 (& kernelTime) + fileTimeToInt64 (& userTime)) /
(s_numberOfProcessors * 10000));
}
/* ......................................................................... */
/* define min elapsed time (in units of 10E-7 sec): */
#define MIN_ELAPSED_TIME (10000)
/*
* Class: com_vladium_utils_SystemInformation
* Method: getProcessCPUUsage
* Signature: ()D
*/
JNIEXPORT jdouble JNICALL
Java_com_vladium_utils_SystemInformation_getProcessCPUUsage (JNIEnv * env, jclass cls)
{
FILETIME creationTime, exitTime, kernelTime, userTime, nowTime;
LONGLONG elapsedTime;

GetProcessTimes (s_currentProcess, & creationTime, & exitTime, & kernelTime, & userTime);
GetSystemTimeAsFileTime (& nowTime);
/*
NOTE: win32 system time is not very precise [~10ms resolution], use
sufficiently long sampling intervals if you make use of this method.
*/

elapsedTime = fileTimeToInt64 (& nowTime) - fileTimeToInt64 (& creationTime);

if (elapsedTime < MIN_ELAPSED_TIME)
return 0.0;
else
return ((jdouble) (fileTimeToInt64 (& kernelTime) + fileTimeToInt64 (& userTime))) /
(s_numberOfProcessors * elapsedTime);
}
#undef MIN_ELAPSED_TIME
/* ------------------------------------------------------------------------- */
/* end of file */
==========================
here is the header file code.
====
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_vladium_utils_SystemInformation */
#ifndef _Included_com_vladium_utils_SystemInformation
#define _Included_com_vladium_utils_SystemInformation
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_vladium_utils_SystemInformation
* Method: getProcessID
* Signature: ()I
*/
JNIEXPORT jint
JNICALL Java_com_vladium_utils_SystemInformation_getProcessID (JNIEnv *, jclass);
/*
* Class: com_vladium_utils_SystemInformation
* Method: getProcessCPUTime
* Signature: ()J
*/
JNIEXPORT jlong
JNICALL Java_com_vladium_utils_SystemInformation_getProcessCPUTime (JNIEnv *, jclass);
/*
* Class: com_vladium_utils_SystemInformation
* Method: getProcessCPUUsage
* Signature: ()D
*/
JNIEXPORT jdouble
JNICALL Java_com_vladium_utils_SystemInformation_getProcessCPUUsage (JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif
#endif
=========

And final question that what is the dll(in windows I think) files which we load at runtime using System.loadLibrary().
How its created or it is already available.
In linux is the process is different or same.
plz reply as soon as possible
thanks & regards,
manish malhotra
20 years ago
What is/are the system calls that I need to use to identify what the CPU and RAM usage percentage.
I want to use C code to get the System Usage in linux OSplateform.
And finnaly use jni concept to call the C function and get the Sys. usage info.
Act. I downloaded code for this from a site but its for win32 plateform. And the C file is giving error, I think some system call are plateform specific & that is giving problem like.
1. GetCurrentProcess ()
2. GetProcessTimes(
etc.
==========================
here is the C code.
/* ------------------------------------------------------------------------- */
/*
* An implementation of JNI methods in com.vladium.utils.SystemInformation
* class. The author compiled it using Microsoft Visual C++ but the code
* should be easy to use with any compiler for win32 platform.
*
* For simplicity, this implementaion assumes JNI 1.2+ and omits error handling.
*
* (C) 2002, Vladimir Roubtsov [vlad@trilogy.com]
*/
/* ------------------------------------------------------------------------- */
#include <windows.h>
#include <process.h>
#include <winbase.h>
#include "com_vladium_utils_SystemInformation.h"
static jint s_PID;
static HANDLE s_currentProcess;
static int s_numberOfProcessors;
/* ------------------------------------------------------------------------- */
/*
* A helper function for converting FILETIME to a LONGLONG [safe from memory
* alignment point of view].
*/
static LONGLONG
fileTimeToInt64 (const FILETIME * time)
{
ULARGE_INTEGER _time;
_time.LowPart = time->dwLowDateTime;
_time.HighPart = time->dwHighDateTime;
return _time.QuadPart;
}
/* ......................................................................... */
/*
* This method was added in JNI 1.2. It is executed once before any other
* methods are called and is ostensibly for negotiating JNI spec versions, but
* can also be conveniently used for initializing variables that will not
* change throughout the lifetime of this process.
*/
JNIEXPORT jint JNICALL
JNI_OnLoad (JavaVM * vm, void * reserved)
{
SYSTEM_INFO systemInfo;

s_PID = _getpid ();
s_currentProcess = GetCurrentProcess ();
GetSystemInfo (& systemInfo);
s_numberOfProcessors = systemInfo.dwNumberOfProcessors;
return JNI_VERSION_1_2;
}
/* ......................................................................... */
/*
* Class: com_vladium_utils_SystemInformation
* Method: getProcessID
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_com_vladium_utils_SystemInformation_getProcessID (JNIEnv * env, jclass cls)
{
return s_PID;
}
/* ......................................................................... */
/*
* Class: com_vladium_utils_SystemInformation
* Method: getProcessCPUTime
* Signature: ()J
*/
JNIEXPORT jlong JNICALL
Java_com_vladium_utils_SystemInformation_getProcessCPUTime (JNIEnv * env, jclass cls)
{
FILETIME creationTime, exitTime, kernelTime, userTime;

GetProcessTimes (s_currentProcess, & creationTime, & exitTime, & kernelTime, & userTime);
return (jlong) ((fileTimeToInt64 (& kernelTime) + fileTimeToInt64 (& userTime)) /
(s_numberOfProcessors * 10000));
}
/* ......................................................................... */
/* define min elapsed time (in units of 10E-7 sec): */
#define MIN_ELAPSED_TIME (10000)
/*
* Class: com_vladium_utils_SystemInformation
* Method: getProcessCPUUsage
* Signature: ()D
*/
JNIEXPORT jdouble JNICALL
Java_com_vladium_utils_SystemInformation_getProcessCPUUsage (JNIEnv * env, jclass cls)
{
FILETIME creationTime, exitTime, kernelTime, userTime, nowTime;
LONGLONG elapsedTime;

GetProcessTimes (s_currentProcess, & creationTime, & exitTime, & kernelTime, & userTime);
GetSystemTimeAsFileTime (& nowTime);
/*
NOTE: win32 system time is not very precise [~10ms resolution], use
sufficiently long sampling intervals if you make use of this method.
*/

elapsedTime = fileTimeToInt64 (& nowTime) - fileTimeToInt64 (& creationTime);

if (elapsedTime < MIN_ELAPSED_TIME)
return 0.0;
else
return ((jdouble) (fileTimeToInt64 (& kernelTime) + fileTimeToInt64 (& userTime))) /
(s_numberOfProcessors * elapsedTime);
}
#undef MIN_ELAPSED_TIME
/* ------------------------------------------------------------------------- */
/* end of file */
==========================
here is the header file code.
====
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_vladium_utils_SystemInformation */
#ifndef _Included_com_vladium_utils_SystemInformation
#define _Included_com_vladium_utils_SystemInformation
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_vladium_utils_SystemInformation
* Method: getProcessID
* Signature: ()I
*/
JNIEXPORT jint
JNICALL Java_com_vladium_utils_SystemInformation_getProcessID (JNIEnv *, jclass);
/*
* Class: com_vladium_utils_SystemInformation
* Method: getProcessCPUTime
* Signature: ()J
*/
JNIEXPORT jlong
JNICALL Java_com_vladium_utils_SystemInformation_getProcessCPUTime (JNIEnv *, jclass);
/*
* Class: com_vladium_utils_SystemInformation
* Method: getProcessCPUUsage
* Signature: ()D
*/
JNIEXPORT jdouble
JNICALL Java_com_vladium_utils_SystemInformation_getProcessCPUUsage (JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif
#endif
=========

And final question that what is the dll(in windows I think) files which we load at runtime using System.loadLibrary().
How its created or it is already available.
In linux is the process is different or same.
plz reply as soon as possible
thanks & regards,
manish malhotra
20 years ago
Hi ,
U can use the Dougs code,the class called PooledExecutor for thread pool which maintains the pool as its own with implementing sych.
Use method execute(Runnable r);
Param : ur thread class object, it internally calls the passed object run method.
If u wanna queue type of pool u will find one constructor which is having BoundedBuffer as param.
U can use that also.
interruptAll() method to interrupt all the threads.
Then u have to find this thread interruption in ur run code of the thread class with this code.
if(Thread.interrupted) {
//do
} else {
// do
}
This is wat u hav posted.
--------------------------------------------------------------------------------
I am having one role combo with some roles.I also have a list box with a list of associates. Based on the role i have selected i need to select the associates already having that role from list box.
for that i have written the following code.
<%
if(rs!=null)
{
while(rs.next())
{
rs1 = st.executeQuery("select associate_id from project_associate where project_id = " + proj + " and role_id = " +role);
if(rs1!=null)
{
while(rs1!=null)
{
if(rs1.getInt("associate_id") == rs.getInt("associate_id"))
{
%>
<option value="<%=rs.getInt("associate_id")%>" selected><%=rs.getString("associate_fullname")%></option>
<%
}
else
{
%>
<option value="<%=rs.getInt("associate_id")%>"><%=rs.getString("associate_fullname")%></option>
<%
}
}
}
%>
<%
}
if(rs1!=null)
{
rs1.close();
rs1 = null;
}
}
%>
</select>

------------------------------------
You code the 2nd while loop as.
while(rs1!=null) but it should be
while(rs1.next())...
That is the problem.
change & then try to execute.
regards,
Manish Malhotra
Hi All,
Can u please solve this problem urgently.
Im getting '#' and '&' values from the test field from a JSP in the servlet but it is getting as their html representation as
for # = #
and for & = &
I think it could be solved using the character encoding. Is it correct or not ? And even if it is correct I dont know how to do this.
Please give me the solution.
form code is--->>
<form autocomplete="off" name="thisForm" method="post"
>
and tag is -->
<input class="Xinput" type="text" name="keyword" size="25" maxlength="50" />
regards,
Manish Malhotra
20 years ago
JSP
Im facing problem of threads while calling different methods of different classes from Servelts.
My scenario is that there could be different users those could access the same servlets simoltaneously & from the service method Im callind different methods of the beans/simple classes which are interactig with database also.
If more then two users are accessing the same screen or other using the same servlet continuosly then its giving abrupt result. I know that every time the servlets called having the same instance but re exicuted the service methods. But I dnt know wat is happening.
And finnaly I made all the methods of my bean as sysnchronized & variables as volatile & finally made the call of the classes from servlet from the Synchronized block itself. But still get errors.
can any body plz help me. Its very urgent.Plz.....
regds,
Manish Malhotra

Originally posted by Mark Spritzler:
And instance variables are not thread safe. The only thing thread safe in a Servlet are local variables. See my last night reading helped already.
If you are calling JavaBeans/other classes from your Servlet you need to make them threadsafe the same way as in any Java class would.
Mark


Thx to both of u 4 ur reply. But can u tell me that how to make the JavaBeans/other classes objects threadsafe as u r telling. Can I make all the variables locally defined in the method srevice & then made the service method synchronized.
Right now I hv done the service method & class methods synchronized & make bean variables as volatile.Its seems to be working fine.
But , I think it is not a good practice becz it will overloaded the servlet/classes.
Can anybody of u just give me more description.
Redgs,
Manish Malhotra
20 years ago
Im facing problem of threads while calling different methods of different classes from Servelts.
My scenario is that there could be different users those could access the same servlets simoltaneously & from the service method Im callind different methods of the beans/simple classes which are interactig with database also.
If more then two users are accessing the same screen or other using the same servlet continuosly then its giving abrupt result. I know that every time the servlets called having the same instance but re exicuted the service methods. But I dnt know wat is happening.
And finnaly I made all the methods of my bean as sysnchronized & variables as volatile & finally made the call of the classes from servlet from the Synchronized block itself. But still get errors.
can any body plz help me. Its very urgent.Plz.....
regds,
Manish Malhotra
20 years ago