Static memory utilization in a utility class
I have a servlet calling a utility class, this utility class has a bunch of static methods. One of these static methods is called getStreamCon() returns a http connection to another server(getStreamCon() has few variables whose scope is limited to the metho), I am trying to understand exactly how the memory is utilized and how the code is executed by this utility class when parallel requests hit the servlet,
Thanks
samurais wrote:
I have a servlet calling a utility class, this utility class has a bunch of static methods. One of these static methods is called getStreamCon() returns a http connection to another server(getStreamCon() has few variables whose scope is limited to the metho), I am trying to understand exactly how the memory is utilized and how the code is executed by this utility class when parallel requests hit the servlet,
What is there to understand?
The local method creates local instances. Those take memory until they can be collected.
return httpconnection(url);Presumably you meant "new" in the above.
So if you have 10 threads there will be 10 instances of HttpConnection as long as each of those threads is using it.
Similar Messages
-
Dear Gurus,
I am new to Java and working on a Java Web Application which is already running.
1)
I found that the util class methods are static also not Synchoronised.
I feel this is wrong because if any 2 user accesses the methods concurrently
then those 2 users will not get expected results.
2)
Basically servlets are not thread safe. Then how actually it serves different users who are accessing
concurrently without any issues.
Can any one please clarify me the doubts?
Thanks in advance
GoudhamYou can declare servlets to be multithreaded. Servlet
containers are supposed to be able to instanciate a
different instance of a servlet for every simultanious
request if you tell it to in the servler descriptor.
Tomcat does this, and I'm sure that WebLogic, BEA,
and the Sun on do as well. That way you don't have
to worry about multi-requests hitting one instance of
a servlet object. This does add more overhead, but
sometimes that's ok.To be more precise, you can declare servlets to be non-thread-safe (i.e. SingleThreadModel). This has the affect of preventing concurrent requests from being dispatched to the Servlet instance. Most (in my experience, all) Servlet containers provide the means by which you can set the maximum size of the instance pool for a SingleThreadModel servlet.
Your best bet is to make your Servlet classes stateless and therefore inherently thread safe. To do this, simply don't define any non-final static or non-static fields and never change the state of those fields). This gives you the greatest scalability. If you must, then have your Servlet implement SingleThreadModel and define an appropriately sized instance pool.
Of course this won't do anything directly to deal with helper classes and their thread safety issues.
Chuck -
Namburi,
When you said you used the Reg Exp tool, did you use it only as
preconfigured by the iMT migrate application wizard?
Because the default configuration of the regular expression tool will only
target the files in your ND project directories. If you wish to target
classes outside of the normal directory scope, you have to either modify the
"Source Directory" property OR create another instance of the regular
expression tool. See the "Tool" menu in the iMT to create additional tool
instances which can each be configured to target different sets of files
using different sets of rules.
Usually, I utilize 3 different sets of rules files on a given migration:
spider2jato.xml
these are the generic conversion rules (but includes the optimized rules for
ViewBean and Model based code, i.e. these rules do not utilize the
RequestManager since it is not needed for code running inside the ViewBean
or Model classes)
I run these rules against all files.
See the file download section of this forum for periodic updates to these
rules.
nonProjectFileRules.xml
these include rules that add the necessary
RequestManager.getRequestContext(). etc prefixes to many of the common
calls.
I run these rules against user module and any other classes that do not are
not ModuleServlet, ContainerView, or Model classes.
appXRules.xml
these rules include application specific changes that I discover while
working on the project. A common thing here is changing import statements
(since the migration tool moves ND project code into different jato
packaging structure, you sometime need to adjust imports in non-project
classes that previously imported ND project specific packages)
So you see, you are not limited to one set of rules at all. Just be careful
to keep track of your backups (the regexp tool provides several options in
its Expert Properties related to back up strategies).
----- Original Message -----
From: <vnamboori@y...>
Sent: Wednesday, August 08, 2001 6:08 AM
Subject: [iPlanet-JATO] Re: Use Of models in utility classes - Pease don't
forget about the regular expression potential
Thanks Matt, Mike, Todd
This is a great input for our migration. Though we used the existing
Regular Expression Mapping tool, we did not change this to meet our
own needs as mentioned by Mike.
We would certainly incorporate this to ease our migration.
Namburi
--- In iPlanet-JATO@y..., "Todd Fast" <toddwork@c...> wrote:
All--
Great response. By the way, the Regular Expression Tool uses thePerl5 RE
syntax as implemented by Apache OROMatcher. If you're doing lotsof these
sorts of migration changes manually, you should definitely buy theO'Reilly
book "Mastering Regular Expressions" and generate some rules toautomate the
conversion. Although they are definitely confusing at first,regular
expressions are fairly easy to understand with some documentation,and are
superbly effective at tackling this kind of migration task.
Todd
----- Original Message -----
From: "Mike Frisino" <Michael.Frisino@S...>
Sent: Tuesday, August 07, 2001 5:20 PM
Subject: Re: [iPlanet-JATO] Use Of models in utility classes -Pease don't
forget about the regular expression potential
Also, (and Matt's document may mention this)
Please bear in mind that this statement is not totally correct:
Since the migration tool does not do much of conversion for
these
utilities we have to do manually.Remember, the iMT is a SUITE of tools. There is the extractiontool, and
the translation tool, and the regular expression tool, and severalother
smaller tools (like the jar and compilation tools). It is correctto state
that the extraction and translation tools only significantlyconvert the
primary ND project objects (the pages, the data objects, and theproject
classes). The extraction and translation tools do minimumtranslation of the
User Module objects (i.e. they repackage the user module classes inthe new
jato module packages). It is correct that for all other utilityclasses
which are not formally part of the ND project, the extraction and
translation tools do not perform any migration.
However, the regular expression tool can "migrate" any arbitrary
file
(utility classes etc) to the degree that the regular expressionrules
correlate to the code present in the arbitrary file. So first andforemost,
if you have alot of spider code in your non-project classes youshould
consider using the regular expression tool and if warranted adding
additional rules to reduce the amount of manual adjustments thatneed to be
made. I can stress this enough. We can even help you write theregular
expression rules if you simply identify the code pattern you wish to
convert. Just because there is not already a regular expressionrule to
match your need does not mean it can't be written. We have notnearly
exhausted the possibilities.
For example if you say, we need to convert
CSpider.getDataObject("X");
To
RequestManager.getRequestContext().getModelManager().getModel(XModel.class);
Maybe we or somebody else in the list can help write that regularexpression if it has not already been written. For instance in thelast
updated spider2jato.xml file there is already aCSpider.getCommonPage("X")
rule:
<!--getPage to getViewBean-->
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[CSpider[.\s]*getPage[\s]*\(\"([^"]*)\"]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[CSpider[.\s]*getPage[\s]*\(\"([^"]*)\"]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[getViewBean($1ViewBean.class]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
Following this example a getDataObject to getModel would look
like this:
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[CSpider[.\s]*getDataObject[\s]*\(\"([^"]*)\"]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[CSpider[.\s]*getDataObject[\s]*\(\"([^"]*)\"]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[getModel($1Model.class]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
In fact, one migration developer already wrote that rule andsubmitted it
for inclusion in the basic set. I will post another upgrade to thebasic
regular expression rule set, look for a "file uploaded" posting.Also,
please consider contributing any additional generic rules that youhave
written for inclusion in the basic set.
Please not, that in some cases (Utility classes in particular)
the rule
application may be more effective as TWO sequention rules ratherthan one
monolithic rule. Again using the example above, it will convert
CSpider.getDataObject("Foo");
To
getModel(FooModel.class);
Now that is the most effective conversion for that code if that
code is in
a page or data object class file. But if that code is in a Utilityclass you
really want:
>
RequestManager.getRequestContext().getModelManager().getModel(FooModel.class
So to go from
getModel(FooModel.class);
To
RequestManager.getRequestContext().getModelManager().getModel(FooModel.class
You would apply a second rule AND you would ONLY run this rule
against
your utility classes so that you would not otherwise affect yourViewBean
and Model classes which are completely fine with the simplegetModel call.
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[getModel\(]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[getModel\(]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[RequestManager.getRequestContext().getModelManager().getModel(]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
A similer rule can be applied to getSession and other CSpider APIcalls.
For instance here is the rule for converting getSession calls toleverage
the RequestManager.
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[getSession\(\)\.]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[getSession\(\)\.]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[RequestManager.getSession().]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
----- Original Message -----
From: "Matthew Stevens" <matthew.stevens@e...>
Sent: Tuesday, August 07, 2001 12:56 PM
Subject: RE: [iPlanet-JATO] Use Of models in utility classes
Namburi,
I will post a document to the group site this evening which has
the
details
on various tactics of migrating these type of utilities.
Essentially,
you
either need to convert these utilities to Models themselves or
keep the
utilities as is and simply use the
RequestManager.getRequestContext.getModelManager().getModel()
to statically access Models.
For CSpSelect.executeImmediate() I have an example of customhelper
method
as a replacement whicch uses JDBC results instead of
CSpDBResult.
matt
-----Original Message-----
From: vnamboori@y... [mailto:<a href="/group/SunONE-JATO/post?protectID=081071113213093190112061186248100208071048">vnamboori@y...</a>]
Sent: Tuesday, August 07, 2001 3:24 PM
Subject: [iPlanet-JATO] Use Of models in utility classes
Hi All,
In the present ND project we have lots of utility classes.
These
classes in diffrent directory. Not part of nd pages.
In these classes we access the dataobjects and do themanipulations.
So we access dataobjects directly like
CSpider.getDataObject("do....");
and then execute it.
Since the migration tool does not do much of conversion forthese
utilities we have to do manually.
My question is Can we access the the models in the postmigration
sameway or do we need requestContext?
We have lots of utility classes which are DataObjectintensive. Can
someone suggest a better way to migrate this kind of code.
Thanks
Namburi
[email protected]
[email protected]
[Non-text portions of this message have been removed]
[email protected]
[email protected]Namburi,
When you said you used the Reg Exp tool, did you use it only as
preconfigured by the iMT migrate application wizard?
Because the default configuration of the regular expression tool will only
target the files in your ND project directories. If you wish to target
classes outside of the normal directory scope, you have to either modify the
"Source Directory" property OR create another instance of the regular
expression tool. See the "Tool" menu in the iMT to create additional tool
instances which can each be configured to target different sets of files
using different sets of rules.
Usually, I utilize 3 different sets of rules files on a given migration:
spider2jato.xml
these are the generic conversion rules (but includes the optimized rules for
ViewBean and Model based code, i.e. these rules do not utilize the
RequestManager since it is not needed for code running inside the ViewBean
or Model classes)
I run these rules against all files.
See the file download section of this forum for periodic updates to these
rules.
nonProjectFileRules.xml
these include rules that add the necessary
RequestManager.getRequestContext(). etc prefixes to many of the common
calls.
I run these rules against user module and any other classes that do not are
not ModuleServlet, ContainerView, or Model classes.
appXRules.xml
these rules include application specific changes that I discover while
working on the project. A common thing here is changing import statements
(since the migration tool moves ND project code into different jato
packaging structure, you sometime need to adjust imports in non-project
classes that previously imported ND project specific packages)
So you see, you are not limited to one set of rules at all. Just be careful
to keep track of your backups (the regexp tool provides several options in
its Expert Properties related to back up strategies).
----- Original Message -----
From: <vnamboori@y...>
Sent: Wednesday, August 08, 2001 6:08 AM
Subject: [iPlanet-JATO] Re: Use Of models in utility classes - Pease don't
forget about the regular expression potential
Thanks Matt, Mike, Todd
This is a great input for our migration. Though we used the existing
Regular Expression Mapping tool, we did not change this to meet our
own needs as mentioned by Mike.
We would certainly incorporate this to ease our migration.
Namburi
--- In iPlanet-JATO@y..., "Todd Fast" <toddwork@c...> wrote:
All--
Great response. By the way, the Regular Expression Tool uses thePerl5 RE
syntax as implemented by Apache OROMatcher. If you're doing lotsof these
sorts of migration changes manually, you should definitely buy theO'Reilly
book "Mastering Regular Expressions" and generate some rules toautomate the
conversion. Although they are definitely confusing at first,regular
expressions are fairly easy to understand with some documentation,and are
superbly effective at tackling this kind of migration task.
Todd
----- Original Message -----
From: "Mike Frisino" <Michael.Frisino@S...>
Sent: Tuesday, August 07, 2001 5:20 PM
Subject: Re: [iPlanet-JATO] Use Of models in utility classes -Pease don't
forget about the regular expression potential
Also, (and Matt's document may mention this)
Please bear in mind that this statement is not totally correct:
Since the migration tool does not do much of conversion for
these
utilities we have to do manually.Remember, the iMT is a SUITE of tools. There is the extractiontool, and
the translation tool, and the regular expression tool, and severalother
smaller tools (like the jar and compilation tools). It is correctto state
that the extraction and translation tools only significantlyconvert the
primary ND project objects (the pages, the data objects, and theproject
classes). The extraction and translation tools do minimumtranslation of the
User Module objects (i.e. they repackage the user module classes inthe new
jato module packages). It is correct that for all other utilityclasses
which are not formally part of the ND project, the extraction and
translation tools do not perform any migration.
However, the regular expression tool can "migrate" any arbitrary
file
(utility classes etc) to the degree that the regular expressionrules
correlate to the code present in the arbitrary file. So first andforemost,
if you have alot of spider code in your non-project classes youshould
consider using the regular expression tool and if warranted adding
additional rules to reduce the amount of manual adjustments thatneed to be
made. I can stress this enough. We can even help you write theregular
expression rules if you simply identify the code pattern you wish to
convert. Just because there is not already a regular expressionrule to
match your need does not mean it can't be written. We have notnearly
exhausted the possibilities.
For example if you say, we need to convert
CSpider.getDataObject("X");
To
RequestManager.getRequestContext().getModelManager().getModel(XModel.class);
Maybe we or somebody else in the list can help write that regularexpression if it has not already been written. For instance in thelast
updated spider2jato.xml file there is already aCSpider.getCommonPage("X")
rule:
<!--getPage to getViewBean-->
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[CSpider[.\s]*getPage[\s]*\(\"([^"]*)\"]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[CSpider[.\s]*getPage[\s]*\(\"([^"]*)\"]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[getViewBean($1ViewBean.class]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
Following this example a getDataObject to getModel would look
like this:
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[CSpider[.\s]*getDataObject[\s]*\(\"([^"]*)\"]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[CSpider[.\s]*getDataObject[\s]*\(\"([^"]*)\"]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[getModel($1Model.class]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
In fact, one migration developer already wrote that rule andsubmitted it
for inclusion in the basic set. I will post another upgrade to thebasic
regular expression rule set, look for a "file uploaded" posting.Also,
please consider contributing any additional generic rules that youhave
written for inclusion in the basic set.
Please not, that in some cases (Utility classes in particular)
the rule
application may be more effective as TWO sequention rules ratherthan one
monolithic rule. Again using the example above, it will convert
CSpider.getDataObject("Foo");
To
getModel(FooModel.class);
Now that is the most effective conversion for that code if that
code is in
a page or data object class file. But if that code is in a Utilityclass you
really want:
>
RequestManager.getRequestContext().getModelManager().getModel(FooModel.class
So to go from
getModel(FooModel.class);
To
RequestManager.getRequestContext().getModelManager().getModel(FooModel.class
You would apply a second rule AND you would ONLY run this rule
against
your utility classes so that you would not otherwise affect yourViewBean
and Model classes which are completely fine with the simplegetModel call.
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[getModel\(]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[getModel\(]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[RequestManager.getRequestContext().getModelManager().getModel(]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
A similer rule can be applied to getSession and other CSpider APIcalls.
For instance here is the rule for converting getSession calls toleverage
the RequestManager.
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[getSession\(\)\.]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[getSession\(\)\.]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[RequestManager.getSession().]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
----- Original Message -----
From: "Matthew Stevens" <matthew.stevens@e...>
Sent: Tuesday, August 07, 2001 12:56 PM
Subject: RE: [iPlanet-JATO] Use Of models in utility classes
Namburi,
I will post a document to the group site this evening which has
the
details
on various tactics of migrating these type of utilities.
Essentially,
you
either need to convert these utilities to Models themselves or
keep the
utilities as is and simply use the
RequestManager.getRequestContext.getModelManager().getModel()
to statically access Models.
For CSpSelect.executeImmediate() I have an example of customhelper
method
as a replacement whicch uses JDBC results instead of
CSpDBResult.
matt
-----Original Message-----
From: vnamboori@y... [mailto:<a href="/group/SunONE-JATO/post?protectID=081071113213093190112061186248100208071048">vnamboori@y...</a>]
Sent: Tuesday, August 07, 2001 3:24 PM
Subject: [iPlanet-JATO] Use Of models in utility classes
Hi All,
In the present ND project we have lots of utility classes.
These
classes in diffrent directory. Not part of nd pages.
In these classes we access the dataobjects and do themanipulations.
So we access dataobjects directly like
CSpider.getDataObject("do....");
and then execute it.
Since the migration tool does not do much of conversion forthese
utilities we have to do manually.
My question is Can we access the the models in the postmigration
sameway or do we need requestContext?
We have lots of utility classes which are DataObjectintensive. Can
someone suggest a better way to migrate this kind of code.
Thanks
Namburi
[email protected]
[email protected]
[Non-text portions of this message have been removed]
[email protected]
[email protected] -
How does the JVM handle private class parameters in a utility class?
If I have a class that is public and not labeled as static, but it's constructor is private so that it cannot be instantiated, and all of its parameters and methods are both private and static. The methods modify the private parameters. In this case, the code explicitly is avoiding a singleton pattern, so there isn't even a class being instantiated, so this is a true utility class.
However, the static methods are accessible from multiple objects, and as far as I can tell, the JVM is persisting the parameters in memory beyond the specific thread that called the static method to begin with.
The question I have is how the JVM handles this? Are these private parameters assigned memory and are indeed persisted independent of thread, since there is no class reference. I am working with byte code injection, and the assumption is that a direct reference to a static parameter is much faster to call than having to go through an object reference. Of course, from a programmer point of view, I much prefer the singleton pattern since I am so used to hang my hat on a class reference.
Thanks.entguru wrote:
However, the static methods are accessible from multiple objects...Not if the methods are private, as you seemed to indicate ("all of its parameters and methods are both private and static").
Are these private parameters assigned memory and are indeed persisted independent of thread, since there is no class reference. There is a class reference. It refers to the class, and is obtainable via the class literal; e.g., MyClass.class.
~ -
hi all,
i want to know memory utilization of following code,
when i am creating an new object every time
and when i am using refrence of the object.
panel2.add(Box.createRigidArea(new Dimension(70, 20)));
panel2.add(Box.createRigidArea(new Dimension(70, 20)));
panel2.add(Box.createRigidArea(new Dimension(70, 20)));
panel2.add(Box.createRigidArea(new Dimension(70, 20)));
Dimension d = new Dimension(70,20);
panel2.add(Box.createRigidArea(d));
panel2.add(Box.createRigidArea(d));
panel2.add(Box.createRigidArea(d));
panel2.add(Box.createRigidArea(d));thanks in advance
dayahello,
why the following code giving same memory in both the cases?
import java.awt.Dimension;
import javax.swing.Box;
import javax.swing.JPanel;
public class MemoryUtili {
public static void main (String s[]) {
Dimension dim = new Dimension(70, 20);
JPanel panel2 = new JPanel();
Runtime r = Runtime.getRuntime();
long FreeMem = 0, TotalMem = 0, usedMem = 0, maxMem = 0;
FreeMem = r.freeMemory();
TotalMem = r.totalMemory();
usedMem = TotalMem - FreeMem;
maxMem = r.maxMemory();
System.out.println( "\nMax Memory : " + maxMem +
"\nTotal Memory : " + TotalMem +
"\nUsed Memory : " + usedMem +
"\nFree Memory : " + FreeMem );
panel2.add(Box.createRigidArea(dim));
panel2.add(Box.createRigidArea(dim));
panel2.add(Box.createRigidArea(dim));
panel2.add(Box.createRigidArea(dim));
r = Runtime.getRuntime();
FreeMem = r.freeMemory();
usedMem = TotalMem - FreeMem;
System.out.println( "\nUsed Memory : " + usedMem +
"\nFree Memory : " + FreeMem );
panel2.add(Box.createRigidArea(new Dimension(70, 20)));
panel2.add(Box.createRigidArea(new Dimension(70, 20)));
panel2.add(Box.createRigidArea(new Dimension(70, 20)));
panel2.add(Box.createRigidArea(new Dimension(70, 20)));
r = Runtime.getRuntime();
FreeMem = r.freeMemory();
usedMem = TotalMem - FreeMem;
System.out.println( "\nUsed Memory : " + usedMem +
"\nFree Memory : " + FreeMem );
} -
Follow up on an old thread about memory utilization
This thread was active a few months ago, unfortunately its taken me until now
for me to have enough spare time to craft a response.
From: SMTP%"[email protected]" 3-SEP-1996 16:52:00.72
To: [email protected]
CC:
Subj: Re: memory utilization
As a general rule, I would agree that memory utilzation problems tend to be
developer-induced. I believe that is generally true for most development
environments. However, this developer was having a little trouble finding
out how NOT to induce them. After scouring the documentation for any
references to object destructors, or clearing memory, or garbage collection,
or freeing objects, or anything else we could think of, all we found was how
to clear the rows from an Array object. We did find some reference to
setting the object to NIL, but no indication that this was necessary for the
memory to be freed.
I believe the documentation, and probably some Tech-Notes, address the issue of
freeing memory.
Automatic memory management frees a memory object when no references to the
memory
object exist. Since references are the reason that a memory object lives,
removing
the references is the only way that memory objects can be freed. This is why the
manuals and Tech-Notes talk about setting references to NIL (I.E. freeing memory
in an automatic system is done by NILing references and not by calling freeing
routines.) This is not an absolute requirement (as you have probably noticed
that
most things are freed even without setting references to NIL) but it accelerates
the freeing of 'dead' objects and reduces the memory utilization because it
tends
to carry around less 'dead' objects.
It is my understanding that in this environment, the development tool
(Forte') claims to handle memory utilization and garbage collection for you.
If that is the case, then it is my opinion that it shoud be nearly
impossible for the developer to create memory-leakage problems without going
outside the tool and allocating the memory directly. If that is not the
case, then we should have destructor methods available to us so that we can
handle them correctly. I know when I am finished with an object, and I
would have no problem calling a "destroy" or "cleanup" method. In fact, I
would prefer that to just wondering if Forte' will take care of it for me.
It is actually quite easy to create memory leaks. Here are some examples:
Have a heap attribute in a service object. Keep inserting things into
the heap and never take them out (I.E. forgot to take them out). Since
service objects are always live, everything in the heap is also live.
Have an exception handler that catches exceptions and doesn't do
anything
with the error manager stack (I.E. it doesn't call task.ErrMgr.Clear).
If the handler is activated repeatedly in the same task, the stack of
exceptions will grow until you run out of memory or the task terminates
(task termination empties the error manager stack.)
It seems to me that this is a weakness in the tool that should be addressed.
Does anyone else have any opinions on this subject?
Actually, the implementation of the advanced features supported by the Forte
product
results in some complications in areas that can be hard to explain. Memory
management
happens to be one of the areas most effected. A precise explanation to a
non-deterministic process is not possible, but the following attempts to
explain the
source of the non-determinism.
o The ability to call from compiled C++ to interpreted TOOL and back
to compiled C++.
This single ability causes most of the strange effects mentioned in
this thread.
For C++ code the location of all variables local to a method is not
know
(I.E. C++ compilers can't tell you at run-time what is a variable
and what
isn't.) We use the pessimistic assumption that anything that looks
like a
reference to a memory object is a reference to a memory object. For
interpreted
TOOL code the interpreter has exact knowledge of what is a reference
and what
isn't. But the TOOL interpreter is itself a C++ method. This means
that any
any memory objects referenced by the interpreter during the
execution of TOOL
code could be stored in local variables in the interpreter. The TOOL
interpreter
runs until the TOOL code returns or the TOOL code calls into C++.
This means
that many levels of nested TOOL code can be the source of values
assigned to
local variables in the TOOL interpreter.
This is the complicated reason that answers the question: Why doesn't a
variable that is created and only used in a TOOL method that has
returned
get freed? It is likely that the variable is referenced by local
variables
in the TOOL interpreter method. This is also why setting the
variable to NIL
before returning doesn't seem to help. If the variable in question is a
Array than invoke Clear() on the Array seems to help, because even
though the
Array is still live the objects referenced by the Array have less
references.
The other common occurrence of this effect is in a TextData that
contains a
large string. In this case, invoking SetAllocatedSize(0) can be used
to NIL
the reference to the memory object that actually holds the sequence of
characters. Compositions of Arrays and TextData's (I.E. a Array of
TextData's
that all have large TextDatas.) can lead to even more problems.
When the TOOL code is turned into a compiled partition this effect
is not
noticed because the TOOL interpreter doesn't come into play and
things execute
the way most people expect. This is one area that we try to improve
upon, but it is complicated by the 15 different platforms, and thus
C++ compilers,
that we support. Changes that work on some machines behave
differently on other
machines. At this point in time, it occasionally still requires that
a TOOL
programmer actively address problems. Obviously we try to reduce
this need over
time.
o Automatic memory management for C++ with support for multi-processor
threads.
Supporting automatic memory management for C++ is something that is
not a very
common feature. It requires a coding standard that defines what is
acceptable and
what isn't. Additionally, supporting multi-processor threads adds
its own set of
complications. Luckily TOOL users are insulated from this because
the TOOL to C++
code generator knows the coding standard. In the end you are
impacted by the C++
compiler and possibly the differences that occur between different
compilers and/or
different processors (I.E. Intel X86 versus Alpha.) We have seen
applications that
had memory utilization differences of up to 2:1.
There are two primary sources of differences.
The first source is how compilers deal with dead assignments. The
typical TOOL
fragment that is being memory manager friendly might perform the
following:
temp : SomeObject = new;
... // Use someObject
temp = NIL;
return;
When this is translated to C++ it looks very similar in that temp
will be assigned the
value NULL. Most compilers are smart enough to notice that 'temp' is
never used again
because the method is going to return immediately. So they skip
setting 'temp' to NULL.
In this case it should be harmless that the statement was ignored
(see next example for a different variation.) In more
complicated examples that involve loops (especially long
lived event loops) a missed NIL assignment can lead to leaking the
memory object whose
reference didn't get set to NIL (incidentally this is the type of
problem that causes
the TOOL interpreter to leak references.)
The second source is a complicated interaction caused by history of
method invocations.
Consider the following:
Method A() invokes method B() which invokes method C().
Method C() allocates a temporary TextData, invokes
SetAllocatedSize(1000000)
does some more work and then returns.
Method B() returns.
Method A() now invokes method D().
Method D() allocates something that cause the memory manager to look
for memory objects to free.
Now, even though we have returned out of method C() we have starting
invoking
methods. This causes us to use re-use portions of the C++ stack used to
maintain the history of method invocation and space for local variables.
There is some probability that the reference to the 'temporary' TextData
will now be visible to the memory manager because it was not overwritten
by the invocation of D() or anything invoked by method D().
This example answers questions of the form: Why does setting a local
variable to
NIL and returning and then invoking task.Part.Os.RecoverMemory not
cause the
object referenced by the local variable to be freed?
In most cases these effects cause memory utilization to be slightly
higher
than expected (in well behaved cases it's less than 5%.) This is a small
price to pay for the advantages of automatic memory management.
An object-oriented programming style supported by automatic memory
management makes it
easy to extended existing objects or sets of objects by composition.
For example:
Method A() calls method B() to get the next record from the
database. Method B()
is used because we always get records, objects, of a certain
type from
method B() so that we can reuse code.
Method A() enters each row into a hash table so that it can
implement a cache
of the last N records seen.
Method A() returns the record to its caller.
With manual memory management there would have to be some interface
that allows
Method A() and/or the caller of A() to free the record. This
requires
that the programmer have a lot more knowledge about the
various projects
and classes that make up the application. If freeing doesn'
happen you
have a memory leak, if you free something while its still
being used the
results are unpredictable and most often fatal.
With automatic memory management, method A() can 'free' its
reference by removing
the reference from the hash table. The caller can 'free' its
reference by
either setting the reference to NIL or getting another
record and referring
to the new record instead of the old record.
Unfortunately, this convenience and power doesn't come for free. Consider
the following,
which comes from the Forte' run-time system:
A Window-class object is a very complex beast. It is composed of two
primary parts:
the UserWindow object which contains the variables declared by the
user, and the
Window object which contains the object representation of the window
created in
the window workshop. The UserWindow and the Window reference each
other. The Window
references the Menu and each Widget placed on the Window directly. A
compound Window
object, like a Panel, can also have objects place in itself. These
are typically
called the children. Each of the children also has to know the
identity of it's
Mom so they refer to there parent object. It should be reasonably
obvious that
starting from any object that make up the window any other object
can be found.
This means that if the memory manager finds a reference to any
object in the Window
it can also find all other objects in the window. Now if a reference
to any object
in the Window can be found on the program stack, all objects in the
window can
also be found. Since there are so many objects and the work involved
in displaying
a window can be very complicated (I.E. the automatic geometry
management that
layouts the window when it is first opened or resized.) there are
potentially many
different reference that would cause the same problem. This leads to
a higher than
normal probability that a reference exists that can cause the whole
set of Window
objects to not be freed.
We solved this problem in the following fashion:
Added a new Method called RecycleMemory() on UserWindow.
Documented that when a window is not going to be used again
that it is
preferably that RecycleMemory() is invoked instead
of Close().
The RecycleMemory() method basically sets all references
from parent to
child to NIL and sets all references from child to
parent to NIL.
Thus all objects are isolated from other objects
that make up
the window.
Changed a few methods on UserWindow, like Open(), to check
if the caller
is trying to open a recycled window and throw an
exception.
This was feasible because the code to traverse the parent/child
relationship
ready existed and was being used at close time to perform other
bookkeeping
operations on each of the Widgets.
To summarize:
Automatic memory management is less error prone and more productive but
doesn't come totally for free.
There are things that the programmer can do that assists the memory
manager:
o Set object reference to NIL when known to be correct (this
is the
way the memory is deallocated in an automatic system.)
o Use methods like Clear() on Array and SetAllocatedSize()
on TextData to
that allow these objects to set their internal
references to NIL
when known to be correct.
o Use the RecycleMemory() method on windows, especially very
complicated
windows.
o Build similar type of methods into your own objects when
needed.
o If you build highly connected structures that are very
large in the
number of object involved think that how it might be
broken
apart gracefully (it defeats some of the purpose of
automatic
management to go to great lengths to deal with the
problem.)
o Since program stacks are the source of the 'noise'
references, try
and do things with less tasks (this was one of the
reasons that
we implemented event handlers so that a single task
can control
many different windows.)
Even after doing all this its easy to still have a problem.
Internally we have
access to special tools that can help point at the problem so that
it can be
solved. We are attempting to give users UNSUPPORTED access to these
tools for
Release 3. This should allow users to more easily diagnose problems.
It also
tends to enlighten one about how things are structured and/or point out
inconsistencies that are the source of known/unknown bugs.
Derek
Derek Frankforth [email protected]
Forte Software Inc. [email protected]
1800 Harrison St. +510.869.3407
Oakland CA, 94612I beleive he means to reformat it like a floppy disk.
Go into My Computer, Locate the drive letter associated with your iPod(normally says iPod in it, and shows under removable storage).
Right click on it and choose format - make sure to not have the "quick format" option checked. Then let it format.
If that doesnt work, There are steps somewhere in the 5th gen forum( dont have the link off hand) to try to use the usbstor.sys to update the USB drivers for the Nano/5th gen. -
RE: [iPlanet-JATO] Re: Use Of models in utility classes
Hi all,
if you add the following to your spider2jato.xml
It will automatically map your CSpDataObject.executeImmediate to use
ExecuteImmediateUtil.executeImmediateSelect with the arguments mapped as
well.
Kostas
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[CSpDataObject[.\s]*executeImmediate[\s]*\(([^,]*),([^)]*)\)]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[CSpDataObject[.\s]*executeImmediate[\s]*\(([^,]*),([^)]*)\)]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[ExecuteImmediateUtil.executeImmediateSelect($1,$2,
getRequestContext())]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
-----Original Message-----
From: Matthew Stevens
Cc: vnamboori@y...
Sent: 11/29/01 11:23 AM
Subject: RE: [iPlanet-JATO] Re: Use Of models in utility classes
Namburi,
I have included an example in the file ExecuteImmediateUtil.java
The Yahoo Group will not handle the attached file we will put it in the
Files section shortly.
matt
-----Original Message-----
From: vnamboori@y... [mailto:<a href="/group/SunONE-JATO/post?protectID=081071113213093190112061186248100253094145066046167121181">vnamboori@y...</a>]
Sent: Thursday, November 29, 2001 12:29 PM
Subject: [iPlanet-JATO] Re: Use Of models in utility classes
Matt,
For CSpSelect.executeImmediate() I have an example of custom helpermethod as a replacement which uses JDBC results instead of
CSpDBResult.
Can you send me this example.
Thanks
Namburi
--- In iPlanet-JATO@y..., "Matthew Stevens" <matthew.stevens@E...>
wrote:
Namburi,
I will post a document to the group site this evening which has thedetails
on various tactics of migrating these type of utilities.Essentially, you
either need to convert these utilities to Models themselves or keepthe
utilities as is and simply use the
RequestManager.getRequestContext.getModelManager().getModel()
to statically access Models.
For CSpSelect.executeImmediate() I have an example of custom helpermethod
as a replacement whicch uses JDBC results instead of CSpDBResult.
matt
-----Original Message-----
From: vnamboori@y... [mailto:<a href="/group/SunONE-JATO/post?protectID=081071113213093190112061186248100208071048">vnamboori@y...</a>]
Sent: Tuesday, August 07, 2001 3:24 PM
Subject: [iPlanet-JATO] Use Of models in utility classes
Hi All,
In the present ND project we have lots of utility classes. These
classes in diffrent directory. Not part of nd pages.
In these classes we access the dataobjects and do the
manipulations.
So we access dataobjects directly like
CSpider.getDataObject("do....");
and then execute it.
Since the migration tool does not do much of conversion for these
utilities we have to do manually.
My question is Can we access the the models in the post migration
sameway or do we need requestContext?
We have lots of utility classes which are DataObject intensive.Can
someone suggest a better way to migrate this kind of code.
Thanks
Namburi
[email protected]
For more information about JATO, please visit:
http://developer.iplanet.com/tech/appserver/framework/index.jsp
[Non-text portions of this message have been removed]
For more information about JATO, please visit:
http://developer.iplanet.com/tech/appserver/framework/index.jsp
[Non-text portions of this message have been removed]Hi all,
if you add the following to your spider2jato.xml
It will automatically map your CSpDataObject.executeImmediate to use
ExecuteImmediateUtil.executeImmediateSelect with the arguments mapped as
well.
Kostas
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[CSpDataObject[.\s]*executeImmediate[\s]*\(([^,]*),([^)]*)\)]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[CSpDataObject[.\s]*executeImmediate[\s]*\(([^,]*),([^)]*)\)]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[ExecuteImmediateUtil.executeImmediateSelect($1,$2,
getRequestContext())]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
-----Original Message-----
From: Matthew Stevens
Cc: vnamboori@y...
Sent: 11/29/01 11:23 AM
Subject: RE: [iPlanet-JATO] Re: Use Of models in utility classes
Namburi,
I have included an example in the file ExecuteImmediateUtil.java
The Yahoo Group will not handle the attached file we will put it in the
Files section shortly.
matt
-----Original Message-----
From: vnamboori@y... [mailto:<a href="/group/SunONE-JATO/post?protectID=081071113213093190112061186248100253094145066046167121181">vnamboori@y...</a>]
Sent: Thursday, November 29, 2001 12:29 PM
Subject: [iPlanet-JATO] Re: Use Of models in utility classes
Matt,
For CSpSelect.executeImmediate() I have an example of custom helpermethod as a replacement which uses JDBC results instead of
CSpDBResult.
Can you send me this example.
Thanks
Namburi
--- In iPlanet-JATO@y..., "Matthew Stevens" <matthew.stevens@E...>
wrote:
Namburi,
I will post a document to the group site this evening which has thedetails
on various tactics of migrating these type of utilities.Essentially, you
either need to convert these utilities to Models themselves or keepthe
utilities as is and simply use the
RequestManager.getRequestContext.getModelManager().getModel()
to statically access Models.
For CSpSelect.executeImmediate() I have an example of custom helpermethod
as a replacement whicch uses JDBC results instead of CSpDBResult.
matt
-----Original Message-----
From: vnamboori@y... [mailto:<a href="/group/SunONE-JATO/post?protectID=081071113213093190112061186248100208071048">vnamboori@y...</a>]
Sent: Tuesday, August 07, 2001 3:24 PM
Subject: [iPlanet-JATO] Use Of models in utility classes
Hi All,
In the present ND project we have lots of utility classes. These
classes in diffrent directory. Not part of nd pages.
In these classes we access the dataobjects and do the
manipulations.
So we access dataobjects directly like
CSpider.getDataObject("do....");
and then execute it.
Since the migration tool does not do much of conversion for these
utilities we have to do manually.
My question is Can we access the the models in the post migration
sameway or do we need requestContext?
We have lots of utility classes which are DataObject intensive.Can
someone suggest a better way to migrate this kind of code.
Thanks
Namburi
[email protected]
For more information about JATO, please visit:
http://developer.iplanet.com/tech/appserver/framework/index.jsp
[Non-text portions of this message have been removed]
For more information about JATO, please visit:
http://developer.iplanet.com/tech/appserver/framework/index.jsp
[Non-text portions of this message have been removed] -
Re: [iPlanet-JATO] Use Of models in utility classes
Hi Matt,
Sounds like some of the stuff we need to migrate has a lot in common with
Namburi's project.
I would be very keen to get hold of a copy of the 'tactic' document you
mention below, as well as the sample code you mention to replace CspDBResult
stuff with JDBC results.
Thanks in advance,
Phil
----- Original Message -----
From: Matthew Stevens <matthew.stevens@E...>
Sent: Wednesday, August 08, 2001 7:56 AM
Subject: RE: [iPlanet-JATO] Use Of models in utility classes
Namburi,
I will post a document to the group site this evening which has thedetails
on various tactics of migrating these type of utilities. Essentially, you
either need to convert these utilities to Models themselves or keep the
utilities as is and simply use the
RequestManager.getRequestContext.getModelManager().getModel()
to statically access Models.
For CSpSelect.executeImmediate() I have an example of custom helper method
as a replacement whicch uses JDBC results instead of CSpDBResult.
matt
-----Original Message-----
From: vnamboori@y... [mailto:<a href="/group/SunONE-JATO/post?protectID=081071113213093190112061186248100253094145066046167121181">vnamboori@y...</a>]
Sent: Tuesday, August 07, 2001 3:24 PM
Subject: [iPlanet-JATO] Use Of models in utility classes
Hi All,
In the present ND project we have lots of utility classes. These
classes in diffrent directory. Not part of nd pages.
In these classes we access the dataobjects and do the manipulations.
So we access dataobjects directly like
CSpider.getDataObject("do....");
and then execute it.
Since the migration tool does not do much of conversion for these
utilities we have to do manually.
My question is Can we access the the models in the post migration
sameway or do we need requestContext?
We have lots of utility classes which are DataObject intensive. Can
someone suggest a better way to migrate this kind of code.
Thanks
Namburi
[email protected]
[email protected]Hi Matt,
Sounds like some of the stuff we need to migrate has a lot in common with
Namburi's project.
I would be very keen to get hold of a copy of the 'tactic' document you
mention below, as well as the sample code you mention to replace CspDBResult
stuff with JDBC results.
Thanks in advance,
Phil
----- Original Message -----
From: Matthew Stevens <matthew.stevens@E...>
Sent: Wednesday, August 08, 2001 7:56 AM
Subject: RE: [iPlanet-JATO] Use Of models in utility classes
Namburi,
I will post a document to the group site this evening which has thedetails
on various tactics of migrating these type of utilities. Essentially, you
either need to convert these utilities to Models themselves or keep the
utilities as is and simply use the
RequestManager.getRequestContext.getModelManager().getModel()
to statically access Models.
For CSpSelect.executeImmediate() I have an example of custom helper method
as a replacement whicch uses JDBC results instead of CSpDBResult.
matt
-----Original Message-----
From: vnamboori@y... [mailto:<a href="/group/SunONE-JATO/post?protectID=081071113213093190112061186248100253094145066046167121181">vnamboori@y...</a>]
Sent: Tuesday, August 07, 2001 3:24 PM
Subject: [iPlanet-JATO] Use Of models in utility classes
Hi All,
In the present ND project we have lots of utility classes. These
classes in diffrent directory. Not part of nd pages.
In these classes we access the dataobjects and do the manipulations.
So we access dataobjects directly like
CSpider.getDataObject("do....");
and then execute it.
Since the migration tool does not do much of conversion for these
utilities we have to do manually.
My question is Can we access the the models in the post migration
sameway or do we need requestContext?
We have lots of utility classes which are DataObject intensive. Can
someone suggest a better way to migrate this kind of code.
Thanks
Namburi
[email protected]
[email protected] -
How to measure JSP Memory Utilization
I'm trying to build a tool that will tell me how much resources a JSP is consuming. Am using 1.4.2_14. I'm using a static heap size (1GB) and -Xgc:singlepar. I've created a filter that does a Runtime.totalMemory () - Runtime.freeMemory () before and after a chain to the JSP. To test this I built a simple JSP that I call from a shell script with curl:
<%
int alloc = 131065;
if (null != request.getParameter("alloc"))
alloc = Integer.parseInt(request.getParameter("alloc"));
Object[] o = new Object[alloc];
for (int i = 0; i < o.length; i++)
o[i] = new Object ();
if (null != request.getParameter("clean"))
for (int i = 0; i < o.length; i++)
o[i] = null;
o = null;
out.println("Done with " + o.length);
%>
When running this JSP repeatedly starting with a allocation of 131,064 objects I get a heap growth of 0 until I increment to 131,067. Then I seem to get good information but every so often I'll see a 18MB bump in memory. The size I get for heap growth at 131,067 is 512,288 bytes.
Why can't I see any memory utilization below 512KB?
What is this 18MB bump in memory?
Is there a way for me to get a more accurate measurment?
Thanks,
HariIt's possible that the totalMemory() and freeMemory() calls are not 100% exact all the time; I don't remember exactly how that info is gathered.
There is a way to get very exact memory consumption with JR. Mail me for details.
-- Henrik -
ClassNotFoundException on utility class in JTA Transaction
When using user defined transactions, I am finding I get odd
ClassNotFoundExceptions. I've tested this primarily on NT/2000, but did
also confirm it on Solaris. Can anyone explain it?
The exception only seems to occur if it becomes necessary to throw an
exception from the EJB. If I am not inside a user defined transaction,
there are no problems. (Even if the method is marked as Transacation
Required). Similarly, if no exception is thrown, there is also no problem
(even though I use plenty of other utility classes)
The classes (including the utility class) are all in my deployed jar file
(which is deployed as part of an ear file).
The error message is below:
java.lang.ClassNotFoundException:
com.iknowledge.inext.exception.STInvalidNameException
at
weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.
java:178)
at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:195)
at
weblogic.j2ee.ApplicationManager.loadFromNetwork(ApplicationManager.java:248
at
weblogic.j2ee.ApplicationManager.loadClass(ApplicationManager.java:175)
at
weblogic.rjvm.MsgAbbrevInputStream.readClassDescriptor(MsgAbbrevInputStream.
java:211)
at
weblogic.common.internal.ChunkedObjectInputStream$NestedObjectInputStream.re
adClassDescriptor(ChunkedObjectInputStream.java:290)
at
java.io.ObjectInputStream.inputClassDescriptor(ObjectInputStream.java:906)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:366)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:236)
at
java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1186)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:386)
at
java.io.ObjectInputStream.inputClassFields(ObjectInputStream.java:2263)
at
java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:519)
at
java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1412)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:386)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:236)
at
weblogic.common.internal.ChunkedObjectInputStream.readObject(ChunkedObjectIn
putStream.java:107)
at
weblogic.transaction.internal.PropagationContext.readExternal(PropagationCon
text.java:304)
at
weblogic.common.internal.ChunkedObjectInputStream.readObject(ChunkedObjectIn
putStream.java:97)
at
weblogic.common.internal.ChunkedObjectInputStream.readObjectWL(ChunkedObject
InputStream.java:123)
at
weblogic.rjvm.MsgAbbrevInputStream.readTxContext(MsgAbbrevInputStream.java:1
66)
at
weblogic.rjvm.MsgAbbrevInputStream.readMessageContext(MsgAbbrevInputStream.j
ava:156)
at
weblogic.rjvm.ConnectionManager.dispatch(ConnectionManager.java:581)
at
weblogic.rjvm.t3.T3JVMConnection.dispatch(T3JVMConnection.java:454)
at
weblogic.socket.NTSocketMuxer.processSockets(NTSocketMuxer.java:638)
at
weblogic.socket.SocketReaderRequest.execute(SocketReaderRequest.java:24)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
You closed your Main class with a bracket, so your getConnection() method isn't in a class
public class Main {
/** Creates a new instance of Main */
public Main() {
public static void main(String[] args) {
Connection con = getConnection();
System.out.println("The connection is: " +con );
}That is your entire Main class. Anything below it isn't in the class. -
Using Async calls in a Util class
I have a Utility class that I want to put code in that I'm reusing over and over again. This includes Async.handleEvent calls. If I call an instance of the Util class from a [Test(async)] method, can I use the Async call in that other event?
When I tried this in my code, it said that it "Cannot add asynchronous functionality to methods defined by Test,Before or After that are not marked async" but my [Test] is marked as async. And when I was in the same class, I was able to have non-Test methods make Async calls.
Thanks for the help!
Mocked up Example (please note these are two separate files):
// Test.as
package
import TimerUtil;
public class Test
[Test(async)]
public function waitForTimer():void
TimerUtil.newTimer();
// TimerUtil.as
package
import flash.events.TimerEvent;
import flash.utils.Timer;
import org.flexunit.async.Async;
public class TimerUtil
private static var instance:TimerUtil;
private var timer:Timer;
private static const TIME_OUT:int = 1000;
public static function newTimer() : void
if (!instance) instance = new TimerUtil();
instance.timer = new Timer(1000, 5);
instance.timer.start();
instance.waitForFifthTick();
private function waitForFifthTick() : void
Async.handleEvent(this, instance.timer, TimerEvent.TIMER, handleTimerTick, TIME_OUT);
private function handleTimerTick ( evt:TimerEvent, eventObject:Object) : void
if ( timer.currentCount == 5 )
// We are at the Fifth click, move on.
else
Async.handleEvent(this, instance.timer, TimerEvent.TIMER, handleTimerTick, TIME_OUT);
Message was edited by: zyellowman2
I missed a comma. And a few "instance"sYes, you can put async calls in utility classes or wherever you want. That isn't the issue here though.
In your test you call TimerUtil.newTimer()
That code creates a timer and then returns. Then your test returns. At that moment, FlexUnit sees that your test has finished and that there are no outstanding registered asynchronous events so it declares the test a success. Then, a second later, your other method executes and tries to register an async call. FlexUnit has no idea what test this pertains to, or why this call is being made as it is no longer in the context of the original test, hence the message you are receiving that you can only using Async calls inside of a method marked with a Async... as, in FlexUnit's opion, the method that is executing this code no longer has anything to do with a test with an async param.
The best way to think about this is a chain that cannot be broken. As soon as a method finishes executing with, FlexUnit will declare it a success unless we are waiting on something else (an async event of some sort) That is what the Async syntax really does, it tells the framework not to declare this method a success just yet, and that there is something else we need to account for to make that decision.
So, right now, in your newTimer() you don't let the framework know that you will be waiting for an async event. Therefore, when that method and the test method is over, so is the test.
Mike -
JavaDocError: Utility classes should not have a public or default construct
Hello all,
I am trying to comply with some check style errors that i am getting and i cannot seem to figure out what is going on. I have set all non-data members to private, except for call point public static void main(string[] args) and i am still getting this error. "Utility classes should not have a public or default constructor." I cannot figure out what is going on, any help would be greatly welcomed. My code is posted below.
public final class Main
* Constant Data Member: RECTANGLE
* Purpose: contains the constant string representing a rectangle.
* @deprecated RECTANGLE Representitive string value for a rectangle.
public static final String RECTANGLE = "rectangle";
* Constant Data Member: TRIANGLE
* Purpose: contains the constant string representing a triangle.
* @deprecated TRIANGLE Representitive string value for a triangle.
public static final String TRIANGLE = "triangle";
* Constant Data Member: REGEX_NUMBER_TEST
* Purpose: contains the constant for numerical test within regex method.
* @deprecated REGEX_NUMBER_TEST regex string for digit comparison.
public static final String REGEX_NUMBER_TEST = "^[0-9]+$";
* Constant Data Member: MAX_ARGUMENTS_RECTANGLE
* Purpose: contains the constant for the maximum number of allowed
* arguments coming in from the command line.
* @deprecated MAX_ARGUMENTS_RECTANGLE constant for rectangle argument.
* limit.
public static final int MAX_ARGUMENTS_RECTANGLE = 3;
* Constant Data Member: MAX_ARGUMENTS_TRIANGLE
* Purpose: contains the constant for the maximum number of allowed
* arguments coming in from the command line, in the case of a
* triangle object.
* @deprecated MAX_ARGUMENTS_TRIANGLE constant for triangle argument limit.
public static final int MAX_ARGUMENTS_TRIANGLE = 2;
* Method: main
* Purpose: Is the execution point for the program. It is in charge of
* initiating validation and the creation and application of
* objects and their related draw methods.
* @param args input from the user.
public static void main(final String[] args)
String objectType = null;
int width = 0;
int height = 0;
if(args.length > MAX_ARGUMENTS_RECTANGLE || args.length <
MAX_ARGUMENTS_TRIANGLE || (args.length == MAX_ARGUMENTS_TRIANGLE &&
!isTriangle(args[0])))
// fails
outputErrorMessage();
else
if ((isTriangle(args[0]) && args.length > MAX_ARGUMENTS_TRIANGLE) ||
(!isTriangle(args[0]) && args.length > MAX_ARGUMENTS_RECTANGLE))
// fails becuase triangle should only have one argument
outputErrorMessage();
else
// passes and proceed
objectType = args[0];
if (validNumber(args[1]))
width = Integer.parseInt(args[1]);
if(width == 0)
outputErrorMessage();
else
....Add a private constructor.
private Main() { }
...This way it will be not possible to create an instance because it is not needed to use its static members or methods.
ref : [http://www.javapractices.com/topic/TopicAction.do?Id=40]
Bye. -
Historical CPU/Memory utilization data and xm top interpretation
Hi All,
Can we get historical CPU/Memory utilization data on domU server. xm top command give real-time data.
secondly, how to interpret xm top command output.
xentop - 02:28:25 Xen 3.0-unstable
3 domains: 3 running, 0 blocked, 0 paused, 0 crashed, 0 dying, 0 shutdown
Mem: 16772032k total, 13863520k used, 2908512k free CPUs: 4 @ 2327MHz
NAME STATE CPU(sec) CPU(%) MEM(k) MEM(%) MAXMEM(k) MAXMEM(%) VCPUS NETS NETTX(k) NETRX(k) VBDS VBD_OO VBD_RD VBD_WR SSID
domain1 -----r 18153551 98.7 6299520 37.6 6307840 37.6 2 2 14008639723 134647867139 2 0 7405453 7224743 0
domain2 -----r 13574751 31.2 6299520 37.6 6307840 37.6 2 2 815959711 780254006 2 0 2732 2658 0
Domain-0 -----r 3807938 9.6 819200 4.9 no limit n/a 4 8 0 0 0 0 0 0 0
Does it implies that there are 2 virtual CPUs configured for guest(domain1), which at this moment 98.7% utilized. Doesn't it shows there is capacity problem?
In virtualization, are virtual CPUs dedicated to guests, or CPU cycles are available on demand. If this is the case, then one guest high utilization can slow down other guests as well.
Thanks,
NeerajHi All,
Can we get historical CPU/Memory utilization data on domU server. xm top command give real-time data.
secondly, how to interpret xm top command output.
xentop - 02:28:25 Xen 3.0-unstable
3 domains: 3 running, 0 blocked, 0 paused, 0 crashed, 0 dying, 0 shutdown
Mem: 16772032k total, 13863520k used, 2908512k free CPUs: 4 @ 2327MHz
NAME STATE CPU(sec) CPU(%) MEM(k) MEM(%) MAXMEM(k) MAXMEM(%) VCPUS NETS NETTX(k) NETRX(k) VBDS VBD_OO VBD_RD VBD_WR SSID
domain1 -----r 18153551 98.7 6299520 37.6 6307840 37.6 2 2 14008639723 134647867139 2 0 7405453 7224743 0
domain2 -----r 13574751 31.2 6299520 37.6 6307840 37.6 2 2 815959711 780254006 2 0 2732 2658 0
Domain-0 -----r 3807938 9.6 819200 4.9 no limit n/a 4 8 0 0 0 0 0 0 0
Does it implies that there are 2 virtual CPUs configured for guest(domain1), which at this moment 98.7% utilized. Doesn't it shows there is capacity problem?
In virtualization, are virtual CPUs dedicated to guests, or CPU cycles are available on demand. If this is the case, then one guest high utilization can slow down other guests as well.
Thanks,
Neeraj -
How to monitor phyisical memory utilization
Can anyone let me know how to monitor the physical memory utilization using monitors/rules?
The existing monitor which is there in windows server management pack monitors the virtual memory where as i wanted to monitor physical memoryYou have to create the monitor yourself.
This monitor is called a Static threshold performance monitor. In the counter list, choose % commited bytes
A walkthrough can be found here:
http://technet.microsoft.com/en-us/library/bb309655.aspx
Juke Chou
TechNet Community Support -
Compiling a servlet with utility class
Hello,
I am having trouble compiling a servlet that uses a utility class.
The compiler doesn't seem to recognize the utility class for some reason.
my classpath is set to:
.;C:\ServletDevel;C:\Program Files\Apache Software Foundation\common\lib\servlet-api.jar
the error:
Cannot find symbol: ServletUtilities
the servlet code:
package coreservlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/** test the use of packages and utilities on the server */
public class helloservlet3 extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String title = "Hello (3)";
out.println(ServletUtilities.headWithTitle(title) +
"<body bgcolor=\"#FDF5E6\">\n" +
"<h1>" + title + "</h1>\n" +
"</body></html>");
the utility class:
package coreservlets;
import javax.servlet.*;
import javax.servlet.http.*;
/** time saving static methods */
public class ServletUtilities {
public final static String docType =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
"Transitional//EN\">";
public static String headWithTitle(String title){
return (docType + "\n" + "<html>\n" +
"<head><title>" + title + "</title></head>\n");
any help wouldbe greatly appreciated.Nope still getting an error
helloservlet3.java:17:cannot find symbol
symbol : class ServletUtilities
location: package coreservlets
out.println(coreservlets.ServletUtilities.headWithTitle(title) +
thanks for the help, i'll keep on trying to figure it out.
Maybe you are looking for
-
Why won't some of my MP4s stream to Apple TV (or iPad) via Home Sharing?
Hi all. I've been converting my DVDs, HD-DVDs, and Blu-rays to MP4, using MakeMKV and then Handbrake 0.9.9.5530 64-bit for encoding. I have been intending to play the files on my iPad, both transferring to the device and streaming via Home Sharing. I
-
How do I set up Airport extreme as a remote with Gateway 2wire as a base
I just switched over to sbcglobal from comcast. Before switching, I had been using an APE as a base station connected with ethernet to my G5 and another APE as a remote. With sbcgobal I got a Gateway 2wire modem. What I would like to know is how do I
-
How can i sync all my apple products together for my mail to all be the same?
i have iphone macbook pro and a ipad, and everytime i go into my mail, i have to delete all my emails on each device ! its sooo annoying, i use my hotmail account cos ive had it for years and dont want to change it. help me
-
In Yosemite there is no Sync Manager, how do I sync my blackberry?
I have upgraded to Yosemite and am trying to sync my Blackberry, which keeps telling me I have to switch on Sync Manager on my iMac. However Yosemite no longer uses Sync Manager, so what do I do?
-
User [ anonymous ] is not authorized to invoke AckCommit on a Coordinator
Hi All, While trying to commit a transaction from OSB proxy I am getting the below error. Can anybody faced this issue before. I am using OSB 10.3.1. <Jul 8, 2013 2:47:36 PM GMT+05:30> <Error> <JTA> <server name> <AdminServer> <[ACTIVE] Exec