 |
 |
Index ‹ java-programmer
|
- Previous
- 1
- package and jar filesHi,
I am new to Java. I hope someone can give me a hint.
What is the difference between package and jar files and do you use them ?
thanks
John
- 1
- extract numbers from picture?is this called pattern matching or AI in java? how can you extract a number
that is on a jpeg or bmp/gif/tiff ? is there any java package doing this?
thanks
- 1
- Re:Correct use of exceptionsWhen we talk about exception, it means that in some situation which we think
that it should works this way, but it isn't. For example, when we write
something to connect to remote SMTP server, we assume that the remote server
should be available but actually it is down... In this case, the exception
happened... So we need the exception handling to show our error message to
user and log the error.
Hope this helps!
Guoqi Zheng
http://www.big8reader.com
- 2
- Struts and AA based on a database
Hello:)
I have a question concerning authentification/authorization and
elements visibility on a Web page in Struts. How to manage the
visibility of control elements in a Struts-based application? The
information about users should be stored in a database and not in XML
configuration files. How to use role based or/and function based
authorization system and how to retrieve the rights from a database and
store them in the Principal object? The application is mantained within
Tomcat application server. So, how to do this? Or, being more precise,
is there any open-source library which provides such a functionality or
should I develop everything from scratch? Do you have some examples for
such stuff?
best regards,
Ania
- 3
- Simple question for those who understand recursion well. Please help.I have a tree represented as a linked list of simple objects
(nodeId/parentId pairs) where the root node is the 1st element in the
list. The other nodes are in somewhat random order. The parentId refers
to the parent node.
I want to convert it into a list where the values are in pre-order.
I.e., I want to get this list as follows: ABCDEFGHIJ (see graph below).
I.e., get the 1st node, put in in the list. If it has children, go
through them one by one, get their child nodes, then put the parent in
the list, then the leftmost first, and go from there. I.e., so that
it's ordered in my linked list like this by (letters represent nodeId):
A
/ \
B J
/ | \
C H I
|
D
/|\
E F G
I created the following recursive method but it does not work
correctly. For example, it places the nodes A then B and then J into
the list first, rather than getting to J after adding all the child
nodes. "isOnTheList" checkes whether the item is already in the list.
"getImmediateChildren" returns the list of immediate child nodes
ordered by nodeId
Note: the empty list is passed to the method and is populated with the
result:
public static void orderTree(List list, List treeList) {
if(treeList == null || treeList.size() == 0)
return;
Node child = null; List children = null;
for(int i = 0; i < treeList.size(); i++) {
node = (Node) treeList.get(i);
// get list of children for this node
children = getImmediateChildren(node, treeList);
// if the node is not yet on the list, add it
if(! isOnTheList(node, list) )
list.add(cat);
// if it has children, recurse to add all other nodes
if(children.size() > 0) {
orderTree(list, children);
}
}
}
Any idea what the problem is?
Thanks.
- 4
- [Q] Saving imageI am looking for a solution to how to make a background image
permanent in a Java application.
My application can have a background image, but when it saves its
file, the background image is not included in the saved file. Is there
a convenient (or right) way to save a gif (or jpeg or png) image into
an application file?
Thanks in advance.
Young-Jin
- 6
- Jars built with JDK 1.3 and JDK 1.4 interoperatingThe Runtime Environment is JRE 1.4. The latest code I have written has
been compiled with JDK 1.4. However it depends on some packages written
and compiled with JDK 1.3. Is there anything to look out for in this
kind of setup or should I have to recompile the older code with 1.4? I
have tested the whole thing and it works, but I wanted some more
information. It is a swing code and I need the JProgressBar's
indeterminate state which is available only in JDK 1.4.
Any update is welcome. If there is any document explaining the above,
that would be perfect. I searched but I was not able to find any
reference.
Thanks
JS
- 6
- My bean doesn't APPEAR on my JSP page!Hi, All!
I have this simple bean (below), and i make the .class using JBuilder 7.0.
I tryed to insert this bean into my JSP page:
<%@ page contentType="text/html; charset=windows-1251" %>
<html>
<head>
<title>
Jsp1
</title>
</head>
<jsp:useBean id="bean0" scope="session" class="bean1.KivaHanTester" />
<jsp:setProperty name="bean0" property="*" />
<body>
<h1>
JBuilder Generated JSP
</h1>
</body>
</html>
BUT I CAN't see this bean, when i open my JSP (IExplorer + Apache).
May be i need to init this bean, like init() or show() i don't know.
Thanks.
SOURCE CODE:
package bean1;
import java.awt.*;
public class KivaHan extends Canvas {
private String msg;
private int width, height;
public KivaHan () {
this ("Coffee: 10 lira");
}
public KivaHan (String s) {
this (s, 200, 200);
}
public KivaHan (String s, int width, int height) {
msg = s;
this.width = width;
this.height = height;
setForeground (Color.cyan);
setFont (new Font ("Serif", Font.ITALIC, 24));
setSize (getPreferredSize());
}
public void paint (Graphics g) {
Dimension d = getSize();
FontMetrics fm = g.getFontMetrics();
int len = fm.stringWidth (msg);
int x = Math.max (((d.width - len) / 2), 0);
int y = d.height / 2;
g.drawString (msg, x, y);
}
public Dimension getPreferredSize () {
return new Dimension (width, height);
}
}
package bean1;
public class KivaHanTester extends java.applet.Applet {
public void init () {
add (new KivaHan());
}
}
- 7
- jtreetabledear java professional,
i want to create a grid using jtreetable. i find the sample code in
the java.sun.com. but it is trickly to understand for me. do you
have any code
(simple code) for using the jtreetable ? i want to simple jtreetable
example program with sample data. do you have the code please send me
to my mail id
email***@***.com.
i also search in the net. but i only very less no. sample code related
to jtreetable. that code also so tricky. do you know any link that
contains simple
jtreetable program?
with regards,
balamurugan se
- 8
- batch update as a single transactionHi,
I'm doing a JDBC batch update, writing several thousand rows to a single
table. As I understand it a batch update can partially succeed, so some of
my rows might get written and some not. I'd like the batch update to either
fully succeed or completely fail, commit or rollback in other words. Is that
easy to do? I'm pretty new at this.
Thanks,
John
- 9
- Java GSM encoding from micHi
I'm trying to encode a microphone stream into GSM using
org.tritonus.lowlevel.gsm.Encoder but I am receiving just static noise -
I've checked the raw PCM output and it's fine. Is there anything obvious
that's missing here?
Thanks
__________________________
The mic is opened as:
AudioInputStream ais=null;
DataLine.Info info_mic = new DataLine.Info(TargetDataLine.class,
new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 8000.0f, 16, 1, 2,
8000.0f, false)
);
TargetDataLine mic = (TargetDataLine) AudioSystem.getLine(info_mic);
mic.open();
mic.start();
ais = new AudioInputStream(mic);
_____________________
And the GSM frame encoder is:
/*------*/
byte [] gsmframe(AudioInputStream ais){
byte [] encd = new byte[33];
try{
byte [] b = new byte[320];
ais.read(b,0,b.length);
DataInputStream di = new DataInputStream(new ByteArrayInputStream(b));
short [] buf = new short[160];
short j=0;
for(int k=0; k<buf.length; k++){
j=di.readShort();
buf[k]=j;
}
org.tritonus.lowlevel.gsm.Encoder enc = new
org.tritonus.lowlevel.gsm.Encoder();
enc.encode(buf, encd);
}catch(Exception e){
System.out.println("error with microphone reading "+e);
return null;
}
return encd;
}
/*-------*/
- 10
- struts form population from an object model...flangelli wrote:
<snip>
> I have a business object model with attributes throughout that are
> mapped to different form beans. Every time that a form bean (jsp) is
> returned to the user's browser, I need to have a place to access my
> object model to retrieve the data from and populate the bean before it
> is displayed. So far it seems that the only time an action class is
> given "command" is AFTER the form submission, I need control on a page
> by page basis to retrieve the values from the object model into the
> bean so the jsp can render the beans values.....anyone had a problem
> similar to this? Thanks in advance - Flangelli
There's nothing which "requires" you to forward to a JSP; you could
just as easily forward to an action. The hitch here is that the
ActionForm will be populated according to the request parameters if
you just perform a forward. The solution is simply to specify
redirect="true" in the forwarding action so that the request
parameters get lost.
Just be careful in your validate method when using this mechanism:
you're users will be irked if the first time they see a page it
contains all manner of error messages. Since you often provide a
reset button on a form, the smart way to approach the situation is
to hold off generating errors if all form fields are blank (or
have the default value).
If this doesn't make perfect sense then repost and I'll dig up
some sample code. Or contact me off-line.
- 12
- Eclipse vs NetBeans vs Jbuilder under LinuxHello everyone,
I've tried the above 3 IDEs in the last year and thought I might make some
comments and ask for your thoughts. Just for interest sake and please don't
start a Holy War ;-)
I originally used netBeans for development, but switched over to Jbuilder
because we where doing tomcat/struts development and my boss said it had
better support. I didn't really get to use netBeans struts stuff but it did
seem a bit weak in comparision.
I would have thought Borland would have a great editor, but I find it very
buggy in comparison to netBeans. Some of the things I have had problems
with include the cursor not being moved when you click in the text area
(this tends to screw up click and drag rearrangement of text or do it when
you don't mean too), auto-formatting of code rearranging it until it won't
compile, method parameter popups not always accessable, method parameter
popups not able to show the names of parameters - only the type, and some
others I can't remember right now.
However, the struts support in JBuilder does seem to be better than netBeans
and runs quite well. Over all the IDE also seems a little quicker and I
quite like the way that you can have multiple projects open and flip
between then with ease. netBeans doesn't seem to handle multiple projects
as smoothly as JBuilder.
I also tried Eclipse at home a couple of time in the last 6 months and at
the moment I can't see why many people are using it. On both occasions I
found also sorts of nasty bugs which tended to simple drive me nuts. The
last time time I used it for example, I found that it would not run the
code I had just edited. I.e. if I could load a project, made some changes
and hit the run button, it would run the code without the changes included.
In order to get the changes it, I had to explicitly do a save before each
run. This sounds trivial but can get very annoying, both netBeans and
JBuilder run the code you are editing, not the last saved code.
Eclipse also seemed to have a strange concept of projects. It looked rather
good with being able to see multiple project trees at the same time until
it came to running them. Then it appeared to separate the concept of
running a projects from the projects themselves and I had to effectively
re-setup again. I also found that if I had en error in one project, it
would fail the compile even if I was in another project. So whilst I could
have multiple projects open at a single time, it seemed to have trouble
understanding which projects I was in and what it was to compile. This
resulted in me having to unload/reload projects on a regular basis. I also
remember not being that happy with it's editor either, I can't remember
exactly why right now.
So, I would have to say that at the moment, I would tend to use netBeans for
general development, JBuilder for struts and Eclipse not at all.
--
cio
Derek
- 14
- How do i do if-else condition in Struts ?How do i do if-else condition in Struts ?
logic:equal does not do it . how struts tag could be used in the JSP
page for an if-else condition ?
how to do it ?
Can anybody provide an example ?
- 16
- Mp3 converter to WavHi,
I just need to convert a mp3 file to the Wav format.
Is there any free package existing, or do i have to write my own program ?
In that case, do you know any link that could help me to understand how to
do this ?
Thanks !
|
| Author |
Message |
R. Vince

|
Posted: 2007-6-7 21:42:00 |
Top |
java-programmer, Forcing System.gc()
I have an app that, at one point, really bogs down as so many objects are
created and released in a lengthy process.
I am wondering if I may not be able to improve performance by System.gc() in
some "right" places in my code (wherever those might be!). It seems to me
though, that the gc facilities in Java are so good, that this is something
best left up to the JVM, and NOT mess with putting System.gc() in anyplace?
I am on WinXP / Vista and JRE 1.6.x. TIA, R. Vince
|
| |
|
| |
 |
Eric Sosman

|
Posted: 2007-6-8 0:00:00 |
Top |
java-programmer >> Forcing System.gc()
R. Vince wrote On 06/07/07 09:42,:
> I have an app that, at one point, really bogs down as so many objects are
> created and released in a lengthy process.
>
> I am wondering if I may not be able to improve performance by System.gc() in
> some "right" places in my code (wherever those might be!). It seems to me
> though, that the gc facilities in Java are so good, that this is something
> best left up to the JVM, and NOT mess with putting System.gc() in anyplace?
The usual wisdom is that the JVM has a more accurate
idea of the state of memory than you do. Its decisions
about when to collect garbage, since they are made in
light of the actual run-time memory pressure, are likely
to be better than static decisions you make at coding
time without benefit of the JVM's knowledge.
In very rare cases you might do better than the JVM,
because the knowledge advantage is not entirely one-sided.
The JVM has better information than you do on the current
state and recent history of memory, but has no knowledge
of the program's future behavior. You may be able to
exploit your foreknowledge to choose a better moment for
GC than the JVM would if left to its own devices.
... but such cases are likely to be extremely rare.
About the only scenario I can come up with is a program
that runs in "waves:" it creates a huge population of
objects, then throws nearly all of them away, and then
repeats. You might get some advantage by running GC in
the "troughs," just after the great object die-off and
before the ensuing population boom. But that's "might"
as in "it's conceivable, I suppose," and not a promise of
any benefit -- it's not even a promise of no harm!
Suggestion: Gather some statistics on the actual GC
behavior of your program. If you find that GC is a problem,
your next step should be to find out why it runs so often
and so hard: Are you creating and discarding objects sub-
optimally, as in
String s = "";
for (String s2 : hugeCollectionOfStrings)
s += s2;
Reducing "object churn" will probably do more to help with
GC than quite a lot of GC-centered fiddling. (Memory
profilers may also be of help here.)
If GC is still a problem even after you've done all you
can to use your objects intelligently, then and only then
should you resort to fiddling with the GC itself. And if
you do, be sure to measure what happens and compare with
the original, pre-fiddling measurements: "tuning" GC may
actually have made things worse, and it may be necessary to
"de-tune" it just to recover the status quo ante.
--
email***@***.com
|
| |
|
| |
 |
Philipp Leitner

|
Posted: 2007-6-8 6:49:00 |
Top |
java-programmer >> Forcing System.gc()
> I am wondering if I may not be able to improve performance by System.gc() in
> some "right" places in my code (wherever those might be!). It seems to me
> though, that the gc facilities in Java are so good, that this is something
> best left up to the JVM, and NOT mess with putting System.gc() in anyplace?
Probably. But you can never 'force' the JVM to do garbage collection.
System.gc() will only 'suggest' that now may be a good time to do GC
(but under certain circumstances, I think it has to do with system
load, the JVM might simply ignore the call). Anyway, I think the cost
for calling System.gc() is not huge, so perhaps I think it might be
worth a try.
I for myself remember having used System.gc() exactly once so far - in
one project I was running >200 Unit Tests, and every test case was
creating an in-memory representation of a WSDL file and compiled XML
Schemata using XMLBeans. At some point in the test run the JVM just
stopped with OutOfMemory. Putting a System.gc() at the end of every
single test case solved the problem just nice.
/philipp
|
| |
|
| |
 |
Twisted

|
Posted: 2007-6-8 9:14:00 |
Top |
java-programmer >> Forcing System.gc()
On Jun 7, 6:49 pm, Philipp Leitner <email***@***.com> wrote:
> I for myself remember having used System.gc() exactly once so far - in
> one project I was running >200 Unit Tests, and every test case was
> creating an in-memory representation of a WSDL file and compiled XML
> Schemata using XMLBeans. At some point in the test run the JVM just
> stopped with OutOfMemory. Putting a System.gc() at the end of every
> single test case solved the problem just nice.
Looks like a bug in the JVM you were using. If it required too much
memory, it should have had OOME no matter what. On the other hand, if
it didn't, it shouldn't have no matter what. All reclaimable garbage
is supposed to be reclaimed before OOME is thrown; the JLS specifies
this, absent unusual and non-default GC-behavior commandline options
to the JVM. So the GC at the end of every single test should just have
changed one large pause where the OOME would *otherwise* have been
thrown into lots of little pauses sprinkled throughout the testing
routine. It should not have prevented an OOME, just a large pause.
|
| |
|
| |
 |
Matt Humphrey

|
Posted: 2007-6-8 9:19:00 |
Top |
java-programmer >> Forcing System.gc()
"Philipp Leitner" <email***@***.com> wrote in message
news:email***@***.com...
|> I am wondering if I may not be able to improve performance by System.gc()
in
| > some "right" places in my code (wherever those might be!). It seems to
me
| > though, that the gc facilities in Java are so good, that this is
something
| > best left up to the JVM, and NOT mess with putting System.gc() in
anyplace?
|
| Probably. But you can never 'force' the JVM to do garbage collection.
| System.gc() will only 'suggest' that now may be a good time to do GC
| (but under certain circumstances, I think it has to do with system
| load, the JVM might simply ignore the call). Anyway, I think the cost
| for calling System.gc() is not huge, so perhaps I think it might be
| worth a try.
|
| I for myself remember having used System.gc() exactly once so far - in
| one project I was running >200 Unit Tests, and every test case was
| creating an in-memory representation of a WSDL file and compiled XML
| Schemata using XMLBeans. At some point in the test run the JVM just
| stopped with OutOfMemory. Putting a System.gc() at the end of every
| single test case solved the problem just nice.
Can you explain how your request for gc would prevent an OutOfMemory error?
I thought that OutOfMemory occurs only when gc cannot reclaim any more--it
is never necessary to request gc to prevent OutOfMemory.
Cheers,
Matt Humphrey email***@***.com http://www.iviz.com/
|
| |
|
| |
 |
Arne Vajh鴍

|
Posted: 2007-6-8 10:29:00 |
Top |
java-programmer >> Forcing System.gc()
R. Vince wrote:
> I have an app that, at one point, really bogs down as so many objects are
> created and released in a lengthy process.
>
> I am wondering if I may not be able to improve performance by System.gc() in
> some "right" places in my code (wherever those might be!). It seems to me
> though, that the gc facilities in Java are so good, that this is something
> best left up to the JVM, and NOT mess with putting System.gc() in anyplace?
>
> I am on WinXP / Vista and JRE 1.6.x.
It is most likely that the JVM is much better than your code
to determine what is optimal times to GC and that explicit
calls to System.gc will decrease performance.
Have you tried experimenting with the -X and -XX JVM parameters
that controls GC ?
Arne
|
| |
|
| |
 |
Philipp Leitner

|
Posted: 2007-6-8 18:10:00 |
Top |
java-programmer >> Forcing System.gc()
> Can you explain how your request for gc would prevent an OutOfMemory error?
> I thought that OutOfMemory occurs only when gc cannot reclaim any more--it
> is never necessary to request gc to prevent OutOfMemory.
No, I can't. I really didn't think much about it so far, but it
definitely worked.
/philipp
|
| |
|
| |
 |
Patricia Shanahan

|
Posted: 2007-6-8 21:16:00 |
Top |
java-programmer >> Forcing System.gc()
Philipp Leitner wrote:
>> Can you explain how your request for gc would prevent an OutOfMemory error?
>> I thought that OutOfMemory occurs only when gc cannot reclaim any more--it
>> is never necessary to request gc to prevent OutOfMemory.
>
> No, I can't. I really didn't think much about it so far, but it
> definitely worked.
Here's one random explanation...
Suppose one of the objects has a finalizer that creates some new
objects. That would be fine if it were finalized while there is plenty
of free memory, as would be the case with a System.gc call at the end of
every cycle of the program.
Patricia
|
| |
|
| |
 |
Lew

|
Posted: 2007-6-8 22:12:00 |
Top |
java-programmer >> Forcing System.gc()
Patricia Shanahan wrote:
> Suppose one of the objects has a finalizer that creates some new objects.
What a dark and evil notion.
I catch grief for finalizers that release resources, just in case the regular
methods didn't.
Now that you have me imagining, I conceive of finalizers that spawn new
threads with their own service cycles, external connections, ...
I hope I awaken soon.
--
Lew
|
| |
|
| |
 |
Matt Humphrey

|
Posted: 2007-6-9 0:46:00 |
Top |
java-programmer >> Forcing System.gc()
"Patricia Shanahan" <email***@***.com> wrote in message
news:f4bkqf$icv$email***@***.com...
| Philipp Leitner wrote:
| >> Can you explain how your request for gc would prevent an OutOfMemory
error?
| >> I thought that OutOfMemory occurs only when gc cannot reclaim any
more--it
| >> is never necessary to request gc to prevent OutOfMemory.
| >
| > No, I can't. I really didn't think much about it so far, but it
| > definitely worked.
|
| Here's one random explanation...
|
| Suppose one of the objects has a finalizer that creates some new
| objects. That would be fine if it were finalized while there is plenty
| of free memory, as would be the case with a System.gc call at the end of
| every cycle of the program.
That's brilliant. If the OOM is inevitable, early gcs could delay it. If
it's not inevitable they could prevent it.
I was thinking that early gcs might affect how objects enter generations,
but supposedly that wouldn't matter because the gc before a OOM would always
be as thorough as possible.
Cheers,
Matt Humphrey email***@***.com http://www.iviz.com/
|
| |
|
| |
 |
Eric Sosman

|
Posted: 2007-6-9 1:13:00 |
Top |
java-programmer >> Forcing System.gc()
Matt Humphrey wrote On 06/07/07 21:19,:
> "Philipp Leitner" <email***@***.com> wrote in message
> news:email***@***.com...
> |> I am wondering if I may not be able to improve performance by System.gc()
> in
> | > some "right" places in my code (wherever those might be!). It seems to
> me
> | > though, that the gc facilities in Java are so good, that this is
> something
> | > best left up to the JVM, and NOT mess with putting System.gc() in
> anyplace?
> |
> | Probably. But you can never 'force' the JVM to do garbage collection.
> | System.gc() will only 'suggest' that now may be a good time to do GC
> | (but under certain circumstances, I think it has to do with system
> | load, the JVM might simply ignore the call). Anyway, I think the cost
> | for calling System.gc() is not huge, so perhaps I think it might be
> | worth a try.
> |
> | I for myself remember having used System.gc() exactly once so far - in
> | one project I was running >200 Unit Tests, and every test case was
> | creating an in-memory representation of a WSDL file and compiled XML
> | Schemata using XMLBeans. At some point in the test run the JVM just
> | stopped with OutOfMemory. Putting a System.gc() at the end of every
> | single test case solved the problem just nice.
>
> Can you explain how your request for gc would prevent an OutOfMemory error?
> I thought that OutOfMemory occurs only when gc cannot reclaim any more--it
> is never necessary to request gc to prevent OutOfMemory.
Might a really memory-hungry finalize() cause such
a thing? I imagine that if finalization uses a lot of
memory, running GC early could schedule deceased objects
for finalization while memory is still plentiful, while
postponing GC until memory is scarce might leave too
little for the finalizers' use. (I hasten to add that
I don't say things *would* play out this way, just that
it seems to me that they might -- I'm entirely ready to
be corrected by someone who knows better.)
A memory-hungry finalizer seems an awfully silly
thing to write -- but that doesn't mean nobody writes
them ...
--
email***@***.com
|
| |
|
| |
 |
Mark Space

|
Posted: 2007-6-9 3:33:00 |
Top |
java-programmer >> Forcing System.gc()
Matt Humphrey wrote:
> Can you explain how your request for gc would prevent an OutOfMemory error?
> I thought that OutOfMemory occurs only when gc cannot reclaim any more--it
> is never necessary to request gc to prevent OutOfMemory.
Would it be possible that long running code without garbage collection
left the heap so fragmented that the largest available memory block
wouldn't hold some object that needed to be allocated? That's all I can
think of. I don't know enough about JVM and memory allocation to know
if this is even a likely scenario...
|
| |
|
| |
 |
Twisted

|
Posted: 2007-6-9 3:54:00 |
Top |
java-programmer >> Forcing System.gc()
On Jun 8, 3:33 pm, Mark Space <email***@***.com> wrote:
> Matt Humphrey wrote:
> > Can you explain how your request for gc would prevent an OutOfMemory error?
> > I thought that OutOfMemory occurs only when gc cannot reclaim any more--it
> > is never necessary to request gc to prevent OutOfMemory.
>
> Would it be possible that long running code without garbage collection
> left the heap so fragmented that the largest available memory block
> wouldn't hold some object that needed to be allocated? That's all I can
> think of. I don't know enough about JVM and memory allocation to know
> if this is even a likely scenario...
Shouldn't be. The thorough GC tried before throwing OOME should
compact all the surviving objects into one or two contiguous blocks
(maybe two with generational GC). Heap fragmentation is for C++
programmers to fret about. ;)
As for a finalizer allocating memory, I'd sort of assumed an absence
of such questionable code. If there is one, though, it could explain a
thing or two. And demonstrate why finalizers are evil, and should only
ever be used to make sure file handles and such are (eventually)
released and never to do anything more complicated than close a stream
here or null out a reference there.
|
| |
|
| |
 |
Mark Space

|
Posted: 2007-6-9 8:45:00 |
Top |
java-programmer >> Forcing System.gc()
Twisted wrote:
>
> Shouldn't be. The thorough GC tried before throwing OOME should
> compact all the surviving objects into one or two contiguous blocks
> (maybe two with generational GC). Heap fragmentation is for C++
> programmers to fret about. ;)
Useful to know, thanks. ^_^ I suppose then that Java references can't
be pointers at all, because moving objects in the heap would invalidate
those pointers. And going through the code and updating all references
on the fly seems... ugly, to say the least. Maybe references work
something like handles in the old Mac OS? Pointers to pointers, where
the second pointer is the thing that gets updated when objects on the
heap are re-allocated or moved.
|
| |
|
| |
 |
ram

|
Posted: 2007-6-9 9:39:00 |
Top |
java-programmer >> Forcing System.gc()
Mark Space <email***@***.com> writes:
>I suppose then that Java references can't be pointers at all,
>because moving objects in the heap would invalidate those pointers.
?...) reference values (...) are pointers?
JLS3, 4.3.1.
http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.3.1
|
| |
|
| |
 |
Twisted

|
Posted: 2007-6-9 11:06:00 |
Top |
java-programmer >> Forcing System.gc()
On Jun 8, 9:39 pm, email***@***.com (Stefan Ram) wrote:
> Mark Space <email***@***.com> writes:
> >I suppose then that Java references can't be pointers at all,
> >because moving objects in the heap would invalidate those pointers.
>
> ?...) reference values (...) are pointers?
>
> JLS3, 4.3.1.
>
> http://java.sun.com/docs/books/jls/third_edition/html/typesValues.htm...
Either it uses double indirection, or (more likely) it updates all the
references when it compacts an object. It can do this -- the gc will
have found those references when mapping the object graph and deciding
whether the object was garbage or not.
|
| |
|
| |
 |
Arne Vajh鴍

|
Posted: 2007-6-10 2:32:00 |
Top |
java-programmer >> Forcing System.gc()
Mark Space wrote:
> Twisted wrote:
>> Shouldn't be. The thorough GC tried before throwing OOME should
>> compact all the surviving objects into one or two contiguous blocks
>> (maybe two with generational GC). Heap fragmentation is for C++
>> programmers to fret about. ;)
>
> Useful to know, thanks. ^_^ I suppose then that Java references can't
> be pointers at all, because moving objects in the heap would invalidate
> those pointers. And going through the code and updating all references
> on the fly seems... ugly, to say the least. Maybe references work
> something like handles in the old Mac OS? Pointers to pointers, where
> the second pointer is the thing that gets updated when objects on the
> heap are re-allocated or moved.
I think that it is left to the JVM implementation to decide
how is will do it.
Note that it already to go through a lot of stuff to find out
what can be GC'ed.
Possibility of reuse !
Arne
|
| |
|
| |
 |
Twisted

|
Posted: 2007-6-10 12:16:00 |
Top |
java-programmer >> Forcing System.gc()
On Jun 9, 2:32 pm, Arne Vajh鴍 <email***@***.com> wrote:
> I think that it is left to the JVM implementation to decide
> how is will do it.
>
> Note that it already to go through a lot of stuff to find out
> what can be GC'ed.
>
> Possibility of reuse !
Certainty of reuse. Sun's VM (the defacto reference implementation)
definitely does do this. With generational GC, it determines if an
object is still live, then copies live objects to a growing contiguous
block of them in memory, which becomes the mature generation or some
such terminology. At the time it copies a particular object it has
pointers to that object's inbound references in memory, from when it
determined its reachability, and on copying it diddles them to point
to the object's new location, presumably while suspending the running
code (so-called "stop the world" gc). It may do incremental GCs that
don't copy objects or "stop the world" depending on settings, with
more thorough, "stop the world" compacting collections when necessary
(due to fragmentation, for instance).
|
| |
|
| |
 |
David Gourley

|
Posted: 2007-6-12 5:20:00 |
Top |
java-programmer >> Forcing System.gc()
Twisted wrote:
>
>
> Shouldn't be. The thorough GC tried before throwing OOME should
> compact all the surviving objects into one or two contiguous blocks
> (maybe two with generational GC). Heap fragmentation is for C++
> programmers to fret about. ;)
>
But there is one big, big assumption here: that the only cause of OOME
is exhausting the (Java) heap. Actually this is one of my biggest
annoyances about Java, especially 32-bit implementations.
You can get OOME attempting to create a thread if there isn't memory to
create the thread's stack (which is actually a native memory issue).
You can get OOME from some mixed language classes if the *native* memory
can't get created associated with instances of those classes (there are
some of these in the java library that allocate native memory as well as
Java memory - always close these objects and don't leave for finalisation).
The annoying thing is I've seen situations where OOME is caused by
unfinalized objects with native memory associated which exhaust the
process's address space (without* causing a garbage collect (as garbage
collection is triggered by behaviour of the Java heap, not the overall
address space of the process). It would be good to have some kind of
setting to trigger a garbage collect if a process's size hit some kind
of threshold as well...
Dave
|
| |
|
| |
 |
Twisted

|
Posted: 2007-6-12 11:07:00 |
Top |
java-programmer >> Forcing System.gc()
On Jun 11, 5:20 pm, David Gourley <email***@***.com>
wrote:
> The annoying thing is I've seen situations where OOME is caused by
> unfinalized objects with native memory associated which exhaust the
> process's address space (without* causing a garbage collect (as garbage
> collection is triggered by behaviour of the Java heap, not the overall
> address space of the process). It would be good to have some kind of
> setting to trigger a garbage collect if a process's size hit some kind
> of threshold as well...
This is real screwy. The JVM *should* stop the world and do a complete
gc and finalization and repeat gc and finalization until nothing new
shows up as garbage, when it is about to throw OOME *for any reason*,
and then retry the allocation, before then actually throwing OOME.
(This would require, I suppose, JNI code to call a malloc-substitute
that does this stuff behind the scenes and retries before returning
NULL, or in C++ a custom operator-new that does likewise before
throwing bad_alloc. If malloc and new are already substituted with
versions that generate OOME in the JVM automatically on failure in the
JNI environment, then this is (comparatively) trivial. Otherwise it
may well be nontrivial and likely will not be back-compatible with
legacy JNI-using code.)
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- Java inherited annotationsHello all!
Some times ago the problem was raised... I and my collegs started to
use Java annotations and noticed that our annotations those was made
for java interfaces and their methods didn't accessible in inherited
classes and interfaces... I tried to use the metatag @Inherited but IMHO
it doesn't work correctly. Anyway we have made our own realization of
inherited Java annotations and shared it. So u can use it if you want.
It is free and open source. Can be downloaded from here:
http://www.fusionsoft-online.com/annotation.php
Best Regards,
Michael Milonov
- 2
- Vendor independent data sourceI have an application that I deployed to WebSphere using the default
Struts datasource from it's action. I've been reading about this now
and it sounds like this is not the prefered way to make a database
connection pool. They suggest using the containers, but I want to
remain vendor independent and be able to deploy my application in any
container with little or no changes.
I know there must be a standard non-vendor specific way to create a
connection pool. Can someone tell me what that standard is? Searching
the web just provided me with about 100 different ways to do it, but I
want the "Java Standard" way to do this.
Thanks,
Smitty
- 3
- Snake Sex 1827email***@***.com wrote:
> I like to masterbate with my pet python, i hope you enjoy the pics i posted here of me having a wonerfull snakey time !
>
> http://superbabes.sexpartnerbd.com
> cvgixlemtdskrblgjgfeitxfscjzhrcppyxghjowcxfo
>
leave it out! this is a java programming news group!
try comp.lang.python
W'ell just hang here having a wonderful erm.... "Classy" time! [groan]
- 4
- popupmenu for a cell in a JTableHello
I want to have a popupmenu when I right click on a selected cell in a JTable
(using with a AbtractTableModel). What are steps I should do, please help.
Thank you
S.Hoa
- 5
- Communicating with a servlet using NIO?Is it possible for a client applet to communicate with a servlet using NIO?
I know it's possible using standard IO but I would like to implement a
servlet that accepts NIO connections from clients and interacts with them.
Is this possible? I don't want to use a special port because of firewall
considerations.
--
And loving it,
-Q
_________________________________________________
email***@***.com
(Replace the "SixFour" with numbers to email me)
- 6
- problem faced while using setContentType("Application/csv")Hi.
while i am trying to respond my client with the dilaog using which a
client user could save the file , the file which is to be sent from
server .... i am facing some issues in
setContentType("Application/csv") .... (file type is csv) ... here is
the chunk of code ....
System.out.println("This line gets displayed before setting content
type");
httpservletresponse.setContentType("application/csv");
System.out.println("After setting content type") // This line never
gets displayed
httpservletresponse.setHeader("Content-Disposition","inline;
filename=" +strtemp[1]+".csv" );
try {
File uFile = new File(strFilePath);
int fSize = (int) uFile.length();
FileInputStream fis = new
FileInputStream(uFile);
PrintWriter pw =
httpservletresponse.getWriter();
int c = -1;
while ( (c = fis.read()) != -1) {
pw.print( (char) c);
}
// Close output and input resources.
fis.close();
pw.flush();
pw = null;
}
catch (Exception e) {
System.out.println("Exception is caught
");
e.printStackTrace();
Any suggestion regarding the issue will be highly obliged ...
Regards,
Madni
- 7
- Corba java apllet client communication problemI hava a problem with communication between Java/Corba server based on JDK
ORB with Java/Corba client (applet)
based on the same ORB. I`m using IOR to localize server.
client`s ORB i initialize like that:
Dane proxy = null;
ORB orb = ORB.init(parent, null);
org.omg.CORBA.Object obj = orb.string_to_object(sIOR);
proxy = DaneHelper.narrow(obj);
server`s ORB i initialize like that:
ORB orb = ORB.init(args, null);
POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
rootpoa.the_POAManager().activate();
DaneImpl oDane = new DaneImpl();
org.omg.CORBA.Object ref = rootpoa.servant_to_reference(oDane);
String ior = orb.object_to_string(ref);
It looks like that:
- if i`m trying to run applet throught web site from the same (192.168.0.1)
computer where Corba sever works
everything works fine, i write it in the browser->
http://192.168.0.1//TestCoraba.html
- if i`m trying to run applet throught web site from an other (192.168.0.2)
computer server receive method call
from client but client can`t receive server`s answer and stops, i write it
in the browser-> http://192.168.0.1//TestCoraba.html
Maybe you what i`m doing wrong.
Thanks form any help.
Best Regards - gRabbi
- 8
- Need to know ASAPOur educational counselors are recruiting new people for our home degree program.
We are running this program as an experiment and we feel you may qualify. This program will earn you a fully qualified degree, with transcripts. Currently we are recruiting people with vast knowledge or experience in the field/trade of their choice.
Give our recruiting office a call when you have time.
Thanks
Alexander Piper
Office Number: 1-773-509-4920
We hope to be talking to you soon.
*We are taking calls at anytime in the day or evening.
--
To UNSUBSCRIBE, email to email***@***.com
with a subject of "unsubscribe". Trouble? Contact email***@***.com
- 9
- Drawing ImageHi,
I am developing a login application in which i need to have an image
put on to a JFrame which has several internal frames. (The main frame)
when I use the graphics object, it draws up the image and it disappears
in a few seconds.
I tried to change the background color, but i see only a flash of the
color and it disappears.
It would be extremely helpful is someone could sort this problem for
me.
Thank you,
Sumit
import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import javax.imageio.*;
import java.awt.Graphics.*;
public class Login extends JPanel implements KeyListener ,
ActionListener
{
JFrame mainFrame;
JDesktopPane desktop, background;
JInternalFrame user;
JButton ok, cancel;
JTextField userName;
TextField pass;
JLabel lname,lpass,message,ms;
JMenuBar mb;
JMenu start,view,options,insert,help;
JMenuItem ocm,ccm,print,exit,about;
Boolean connectionManagerStatus;
Image img;
Login()
{
/*
* Basic Theme
*/
try
{
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
}
catch (Exception e)
{
System.out.println(e.toString());
}
/*
* Initializations and addition to the program
*/
mb = new JMenuBar();
desktop = new JDesktopPane();
background = new JDesktopPane();
mainFrame = new JFrame (".:: I . C . E ::. Application");
mainFrame.setJMenuBar(mb);
start = new JMenu ("Start");
view = new JMenu ("View");
options = new JMenu ("Options");
insert = new JMenu ("Insert");
help=new JMenu("help");
start.setMnemonic(KeyEvent.VK_S);
view.setMnemonic(KeyEvent.VK_V);
options.setMnemonic(KeyEvent.VK_O);
insert.setMnemonic(KeyEvent.VK_I);
help.setMnemonic(KeyEvent.VK_H);
mb.add(start);
mb.add(view);
mb.add(options);
mb.add(insert);
mb.add(help);
background.setVisible(true);
background.setSize(640,640);
ocm=new JMenuItem("Open Connection Manager",KeyEvent.VK_O);
ccm = new JMenuItem("Close Connection",KeyEvent.VK_C);
print = new JMenuItem("Print",KeyEvent.VK_P);
exit = new JMenuItem("Exit",KeyEvent.VK_X);
about = new JMenuItem("About Us",KeyEvent.VK_A);
start.add(ocm);
start.add(ccm);
start.addSeparator();
start.add(print);
start.add(exit);
help.add(about);
user = new JInternalFrame("Connection Manager");
lname = new JLabel("USERNAME:");
userName = new JTextField (50);
lpass = new JLabel("PASSWORD:");
pass = new TextField(50);
pass.setEchoChar('*');
ms = new JLabel ("Message From Server: ");
message = new JLabel("3 Wrong attempts and account freezes");
ok = new JButton ("Login");
cancel = new JButton ("Cancel");
ok.setBounds(20,180,100,20);
cancel.setBounds(130,180,100,20);
mainFrame.setUndecorated(false);
mainFrame.add(desktop);
mainFrame.setFocusable(true);
options.setEnabled(false);
insert.setEnabled(false);
view.setEnabled(false);
print.setEnabled(false);
ocm.setEnabled(false);
ccm.setEnabled(false);
connectionManagerStatus=true;
mainFrame.setSize(Toolkit.getDefaultToolkit().getScreenSize());
desktop.setSize(640,480);
lname.setBounds(10,40,70,20);
userName.setBounds(100,40,130,20);
lpass.setBounds(10,100,100,20);
pass.setBounds(100,100,130,20);
ms.setBounds(15,270,140,20);
message.setBounds(10,320,240,20);
message.setForeground(Color.darkGray);
user.setLayout(null);
user.getContentPane().add(lname);
user.getContentPane().add(userName);
user.getContentPane().add(lpass);
user.getContentPane().add(pass);
user.getContentPane().add(ok);
user.getContentPane().add(cancel);
user.getContentPane().add(ms);
user.getContentPane().add(message);
user.setResizable(false);
//JLabel s = new JLabel("XXXXXXXXXXXXXXx");
ok.setEnabled(false);
user.setVisible(true);
user.setSize(340,480);
desktop.setLocation(30,200);
desktop.add(user);
user.setLocation(30,200);
//user.setBorder(BorderFactory.createRaisedBevelBorder());
// adding listeners
userName.addKeyListener(this);
exit.addActionListener(this);
cancel.addActionListener(this);
ocm.addActionListener(this);
pass.addKeyListener(this);
ok.addActionListener(this);
mainFrame.setVisible(true);
mainFrame.validate();
l();
}
public void actionPerformed (ActionEvent ae)
{
if ((ae.getSource())==exit)
{
System.exit(0);
}
else if ((ae.getSource())==cancel)
{
user.setVisible(false);
userName.setText(null);
pass.setText(null);
ocm.setEnabled(true);
}
else if ((ae.getSource())==ocm)
{
user.setVisible(true);
ocm.setEnabled(false);
}
else if ((ae.getSource())==ok)
{
user.setVisible(false);
ocm.setEnabled(false);
ccm.setEnabled(true);
System.out.println(pass.getText());
}
}
public void keyPressed (KeyEvent ke)
{
if ((ke.getComponent())==userName)
{
if (userName.getText()!=null)
{
ok.setEnabled(true);
}
else
{
ok.setEnabled(false);
}
}
else if ((ke.getComponent())==pass)
{
}
}
public void keyReleased (KeyEvent ke1)
{
}
public void keyTyped (KeyEvent ke2)
{
}
public static void main (String args [])
{
Login obj = new Login ();
}
public void l()
{
Graphics g = mainFrame.getGraphics();
try
{
img = Toolkit.getDefaultToolkit().getImage("d:\\loge.bmp");
g.drawImage(img,1024,800,null);
System.out.println("Image drawn");
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
}
- 10
- Why is creating a simple component with Netbeans IDE fails with an exceptionHi
steps:
using a mounted sub-directory named TESTING
Template: In the Explorer, select the TESTING node and choose File New "Java
Gui Form" Bean Form. click next
Target Location: In Name enter TargetName. click next
Basic Class definition: Superclass select javx.swing.JComponent. click
finish
Why do you get an exception :
Cannot determine form type (javax.swing.JComponent)
Please make sure the class is a JavaBean
The form cannot be opened.
I am trying to build a component similar to a JLabel which is a JavaBean
derived directly from a JComponent.
Which step is missing or am I completly out to lunch.
Thanks in advance
Andre
- 11
- Tomcat, Oracle, connection pooling, BLOBsI have a rather strange problem with Tomcat's connection pooling and
the Oracle JDBC driver when using BLOBs that seems to be related to
class loading.
My configuration:
Tomcat 5.0.27
Oracle 9i
ojdbc14.jar is in $CATALINA_HOME/common/lib (and nowhere else)
The datasource is configured in server.xml
Everything works perfectly as long as I don't configure the datasource
in the server.xml file (including reading/writing BLOBs).
Once I use the datasource configuration in server.xml everything
except Oracle's BLOB implementation works (means: I can access the
tables, insert, select etc., but I can't read/write BLOBs)).
The problem is with class loading:
System.out.println(getConnection() instanceof
oracle.jdbc.driver.OracleConnection);
System.out.println(getConnection().getClass().getName());
results in:
false
oracle.jdbc.driver.OracleConnection
So the connection is of the expected type, but the type has been
loaded with the wrong class loader. This leads to a ClassCastException
in the Oracle JDBC driver (createTemporary()).
As I told you the JDBC driver is in common/lib and nowhere else, so
the class should be available in the application code.
Any hints ?
- 12
- JDOM stringsHi All !
I have some xml file that contain next tag:
<text>ÐоÑ</text>
I get Element text = ... on this tag and want get string that it contain:
String myText = text.getText();
I hope to see in the myText : 0xD09D 0xD0BE .....
but get next set:
0xC390 0xC29D 0xC390 0xC2BE 0xC391 0xC280 0xC390 .... ?????
what is it 0xC390 ??? And how can I get that I want :) ???
--dima
- 13
- JSP Include IssuesI have a web page using an include file. I am passing params to the
include page using jsp:param but am having some difficulty.
Locally (Windows PC/Tomcat Server, JBuilder) I can include ™ in
the heading1 param - when I put this live (Linux/Tomcat Server) the
heading1 text is cut off after the &. There is no error message from
Java (unless it is a System.out.print type error).
Does anyone have any suggestions as to why this is not working and how
I can resolve it?
<jsp:include flush="true" page="/inc/nav.jsp">
<jsp:param name="heading1" value="Business Web Design:
<em>Functional, Findable, Accessible ™</em>" />
<jsp:param name="pageTitle" value="Home" />
</jsp:include>
Regards,
Rick
www.e-connected.com
- 14
- Why jdk-1.5.0 and diablo-jdk-1.5.0 does not containOn Tue, Jan 08, 2008 at 01:04:22PM +0300, Alex Pivovarov wrote:
> Could you tell me why jdk-1.5.0 and diablo-jdk-1.5.0 does not contain
> sunpkcs11.jar in jre/lib/ext?
> Or I was doing something wrong when I install them. I use default options --
> the only think I uncheck is browser plugin.
Because the source code and build infrastructure aren't included for either
the JAR or the native library in the source that Sun distributes(*). You
could copy the included Linux/Solaris JARs over, but then you need to build
the corresponding native library somehow.
* - Actually, the source is there, but its bundled up and there is no
build infrastructure.
Thats my recollection at least.
--
Greg Lewis Email : email***@***.com
Eyes Beyond Web : http://www.eyesbeyond.com
Information Technology FreeBSD : email***@***.com
_______________________________________________
email***@***.com mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-java
To unsubscribe, send any mail to "email***@***.com"
- 15
- CeWolf and JSPHi, I'm Claudio, I'm a student and I want to use ceWolf for my graphs
in JSP pages. I visited the web site http://cewolf.sourceforge.net/
and i followed each pass of the tutorial but I don't visualize the
chart, there is an exeption: NullPointerException in cewolf_jsp.java
row 202:
int _jspx_eval_cewolf_img_0 = _jspx_th_cewolf_img_0.doStartTag();
In the JSP, if I delete this row:
<cewolf:img chartid="line" renderer="cewolf" width="400"
height="300"/>
all go ok, but obviously there isn't the chart.
Could you help me, please!
Thanks, Claudio
|
|
|