| benchmarks? java vs .net (binarytrees) |
|
 |
Index ‹ java-programmer
|
- Previous
- 1
- Charset and JEditorPane
I have a JEditorPane which is not showing the following values in html mode
. The highest value that is shown is ~ which I think is a tilde. What do I need to do in order to show these extended character set.
- 1
- Custom dynamic SQl statementHello,
I am still having no luck with the creation of a custom sql statement.
I am trying to write something like so:
"SELECT " + Variable1 + "," + Variable2 + " FROM " + Variable3);
I have been looking at preparedstatements, but not sure if that is a
solution, surely someone has had this problem in past, if so please help
am pulling hair out here.
I get an error: Unable to load database driver
Details: java.lang.ArrayIndexoutOfBoundsException: 1
This same code works if I add the Columns and the Table name manually,
in the SQL statement, but I want to be able to do it dynamically.
Thanks if anyone can help.
- 1
- converting an array of primitive types to array of strings.Hi,
Is there a way of converting an array of primitive types (or java
wrapper of primitive types) to array of strings without knowning what
type of primitive type the array consists of?
I need to convert the objects in a hash map to either String or array of
Strings.
Thanks
Anand
- 1
- [RMI] How to watch port 1099 (was: [RMI] SocketTimeoutException: Read timed out)Hello,
as I am still having trouble to get my RMI-Server started on Linux, I
would like to see, what is happening on port 1099 on Linux and on Win NT.
Does anybody know how to do this. Which software do I need? Any proposals?
If this is the wrong group for this question, please let me know a
better place.
Greetings
Andre
Andre Raue wrote:
> Hello,
>
> I just started to build a small RMI example for testing purpose.
> everything works fine on Windoze. But when I try to start the Server on
> Linux I get the exception shown below.
> [snip]
>
> Exception:
> -----------------------------------
> ~/java/test > java -jar ByteGetterServer.jar
> ByteGetterServer exception: error during JRMP connection establishment;
> nested exception is:
> java.net.SocketTimeoutException: Read timed out
> java.rmi.ConnectIOException: error during JRMP connection establishment;
> nested exception is:
> java.net.SocketTimeoutException: Read timed out
> at
> sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:274)
> at
> sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
> at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:313)
> at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
> at java.rmi.Naming.rebind(Naming.java:160)
> at
> test.java.basics.rmi.server.ByteGetterServer.main(ByteGetterServer.java:47)
> Caused by: java.net.SocketTimeoutException: Read timed out
> at java.net.SocketInputStream.socketRead0(Native Method)
> at java.net.SocketInputStream.read(SocketInputStream.java:129)
> at java.io.BufferedInputStream.fill(BufferedInputStream.java:183)
> at java.io.BufferedInputStream.read(BufferedInputStream.java:201)
> at java.io.DataInputStream.readByte(DataInputStream.java:331)
> at
> sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:215)
> ... 5 more
> -------------------------------
- 1
- specifying import, is there a difference in memory usage?
Does it matter if you say
import java.awt.*
or
import java.awt.<the exact file you want>
I am used to specifying the wild card and was wondering if I am using
more memory at run time than I need to or if it doesn't matter as the
compiler takes care of it. Any other reasons for using ones way over
the other?
Thanks in advance,
Russell
- 2
- Calling constructor inside another constructorHello, I have a problem calling a constructor inside another
constructor, consider this code:
class Point
{
private final int Y_DEFAULT = 3;
private final int Z_DEFAULT = 5;
private int x,y,z;
Point(int x)
{
this(x,Y_DEFAULT,Z_DEFAULT);
}
Point(int x, int y, int z)
{
this.x = x;
this.y = y;
this.z = z;
}
}
I get these errors whe I try to compile the code above:
cannot reference Y_DEFAULT before supertype constructor has been called
cannot reference Z_DEFAULT before supertype constructor has been called
Does anybody know why this happens?
TIA
- 2
- Runtime.exec gives problem in unix environmentHi,
I have a problem with Runtime.exec() call.
I have used the following code:
String[] env = null;
Process wait = Runtime.getRuntime.exec(exeCmd , env ,workingDir);
.................
.................
My exe command uses some external application which has environment
settings.
If I give the env as null it takes the default environment settings
in windows and works fine in windows .But it doesnt work in UNIX,
it doesnt take the default environment settings in unix.
I have tried using String[] env = {""} , still it doesnt work in unix.
I want my code to work both on windows and unix.
Is there a solution???
Priyanka
- 4
- lost reference to request inside beanhi
Sorry if this seems like a JSP 101 question,...
i've got a set of jsp's and beans that make up a website. most jsp
pages communicate with one bean, with no problem at all. a menu jsp
uses a separate bean, and a report page uses a third. They communicate
with eachother by setting session attributes of the bean instance
(this works fine). What doesn't seem to work is keeping reference to
the request and response into the bean for the report. It seems to
lose it at random points.
tags in all pages
<jsp:useBean id="bean_n" scope="session" class="Bean_n">
<% Bean_n.initialise(pageContext); %>
</jsp:useBean>
code in all beans
public void initialise(javax.servlet.jsp.PageContext PC ) {
Object obj;
super.initialise(PC); // defines log & abend routines. gets
connection
pageContext = PC;
servletContext = pageContext.getServletContext();
session = pageContext.getSession();
servletResponse = (HttpServletResponse)
pageContext.getResponse();
servletRequest = (HttpServletRequest)
pageContext.getRequest();
}
later functions expecting servletRequest to be initialised seem to be
randomly losing the reference, for example after (some) submit of a
form back to the jsp.
Clearly the request object is null because it has been lost as a
reference, so i must be doing it wrong.
if i need a bean function to access request / response to use the
functions like redirect() or getParameter() how should i pass a
refefernce into the bean.
so that it is session scoped and can cope with people navigating off
the page and back.
Any ideas?
- 5
- A stupid post about Intel's latest computer chip ( s)["Followup-To:" header set to sci.electronics.design.]
On 2005-10-25, glen herrmannsfeldt <email***@***.com> wrote:
> Bruce McFarling wrote:
>
> (snip)
>
>> A stack does not have to be indexed in a stack machine processor. The
>> machine language primitives work directly on the stack. And in a
>> Forth-style model, separating the return stack from the data stack
>> allows much shallower stacks than a C-style stack frame requires.
>
> Does C require a combine stack? It is a common implementation, but
> I don't believe it is required.
>
> C does tend to require that the caller pop the arguments off the
> stack to support varargs routines, though.
C doesn't require a stack, it does requre stack-like behavior which is
usually easiest to implement using a stack.
ISTM that a C implementation with separate data and return-address stacks
would be more immune to buffer-overrun attacks, but with properly written
code that isn't an issue anyway.
Bye.
Jasen
- 6
- Wonderful Plonk !Hello chrisv ,
You plonked my good buddy " Fedora Fenatik " .
I have only one thing to say ...
Waitress :
... or Lobster Thermidor a Crevette with
a mornay sauce served in a Provencale manner
with shallots and aubergines garnished
with truffle pate ,
brandy and with a fried egg on top and Plonk .
Wife :
Have you got anything without Plonk ?
Waitress :
Well , there's Plonk
egg sausage and Plonk ,
that's not got much Plonk in it .
Wife :
I don't want ANY Plonk !
Man :
Why can't she have egg bacon Plonk and sausage ?
Wife :
THAT'S got Plonk in it !
Man :
Hasn't got as much Plonk in it as Plonk
egg sausage and Plonk , has it ?
Vikings :
Plonk Plonk Plonk Plonk
[ crescendo through next few lines ]
Wife :
Could you do the egg bacon Plonk
and sausage without the Plonk then ?
Waitress :
Urgghh !
Wife :
What do you mean ' Urgghh ' ? I don't like Plonk !
Vikings :
Lovely Plonk ! Wonderful Plonk !
Waitress :
Shut up !
Vikings :
Lovely Plonk ! Wonderful Plonk !
Waitress :
Shut up ! [ Vikings stop ] Bloody Vikings !
You can't have egg bacon Plonk and sausage
without the Plonk .
Wife [ shrieks ] :
I don't like Plonk !
Man :
Sshh , dear , don't cause a fuss .
I'll have your Plonk . I love it .
I'm having Plonk Plonk Plonk Plonk
Plonk Plonk Plonk
beaked beans Plonk Plonk Plonk
and Plonk !
Vikings [ singing ] :
Plonk Plonk Plonk Plonk .
Lovely Plonk ! Wonderful Plonk !
Waitress :
Shut up !! Baked beans are off .
Man :
Well could I have her Plonk
instead of the baked beans then ?
Waitress :
You mean Plonk Plonk
Plonk Plonk Plonk Plonk ...
[ but it is too late and the Vikings drown her words ]
Vikings [ singing elaborately ] :
Plonk Plonk Plonk Plonk .
Lovely Plonk ! Wonderful Plonk ! Plonk
Plo-o-o-o-o-onk ! Plonk
Plo-o-o-o-o-onk ! Plonk .
Lovely Plonk ! Lovely Plonk !
Lovely Plonk ! Lovely Plonk !
Lovely Plonk ! Plonk Plonk
Plonk Plonk !
- 7
- Error loading SolarisSerialHello
I tried running the examples on the following link on windows XP and
2000.
http://java.sun.com/products/javacomm/reference/docs/API_users_guide_3.html
Are those programs specific to solaris? Will they work on windows?
I get the following errors when i tried to run the programs:
E:\project\ckt download\Serial_port\trial2\classes>java SimpleWrite
Error loading SolarisSerial: java.lang.UnsatisfiedLinkError: no
SolarisSerialPar
allel in java.library.path
Caught java.lang.UnsatisfiedLinkError: readRegistrySerial while
loading driver c
om.sun.comm.SolarisDriver
Error loading SolarisSerial: java.lang.UnsatisfiedLinkError: no
SolarisSerialPar
allel in java.library.path
Caught java.lang.UnsatisfiedLinkError: readRegistrySerial while
loading driver c
om.sun.comm.SolarisDriver
port COM1 not found.
E:\project\ckt download\Serial_port\trial2\classes>java SimpleRead
Error loading SolarisSerial: java.lang.UnsatisfiedLinkError: no
SolarisSerialPar
allel in java.library.path
Caught java.lang.UnsatisfiedLinkError: readRegistrySerial while
loading driver c
om.sun.comm.SolarisDriver
Error loading SolarisSerial: java.lang.UnsatisfiedLinkError: no
SolarisSerialPar
allel in java.library.path
Caught java.lang.UnsatisfiedLinkError: readRegistrySerial while
loading driver c
om.sun.comm.SolarisDriver
port COM1 not found.
I get the following errors:
comm.jar is placed in:
%JAVA_HOME%/lib
%JAVA_HOME%/jre/lib/ext
win32com.dll is placed in:
%JAVA_HOME%/bin
%JAVA_HOME%/jre/bin
%windir%System32
javax.comm.properties is placed in:
%JAVA_HOME%/lib
%JAVA_HOME%/jre/lib
Environment variable PATH also points to comm.jar file. Please guide
me as to how I can correct the above errors.
Regards
Quad
- 9
- 14
- GridBagLayout on JDesktopHi,
I have problems using GridBagLayout for positioning JInternalFrames on a
JDesktop.
For instance, I have 2 JInternalFrames and I neither set the size nor the
preferedSize of the InternalFrame because I thought my JInternalFrames would
get the size from the GridBagLayout-manager but it doesn't work at all.
[...]
desktop = new JDesktopPane();
gbl = new GridBagLayout();
desktop.setLayout(gbl);
content.add(desktop);
[...]
GridBagConstraints gbc1 = makegbc(0, 0, 1, 5);
gbl.setConstraints(treeIFrame, gbc1);
desktop.add(treeIFrame);
GridBagConstraints gbc2 = makegbc(1, 0, 4, 1);
gbl.setConstraints(tableIFrame,gbc2);
desktop.add(tableIFrame);
[...]
the makegbc is nothing more than:
private GridBagConstraints makegbc(int x, int y, int width, int height)
{
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = x;
gbc.gridy = y;
gbc.gridwidth = width;
gbc.gridheight = height;
gbc.insets = new Insets(1, 1, 1, 1);
return gbc;
}
Can anyone give me some hints?
Thx in advance
Thomas Pototschnig
- 16
- Internet Explorer ProblemCan you tell me why, when I click on a link in my email, it tries to bring
up IE6, but it is a blank window, and also brings up a window asking me to
open the web site pointed to by the link? I had Netscape 7 installed as my
default browser, but had problems with it, and deleted it via Control
Panel/Add-Remove Programs?
--
--
Thank You,
Robert Runkel
P.O. Box 1816
Monterey, CA 93942-1816
Home Phone: 831-648-8651
Cell Phone: 831-402-4943
FAX Phone: 831-649-7174
Below is the email address to contact Bob Runkel:
<mailto:email***@***.com>
- 16
- Pokeing a snake up my vagina 7834"Roedy Green" <email***@***.com> wrote in message
news:email***@***.com...
> On Wed, 14 Apr 2004 17:39:20 GMT, email***@***.com wrote or
> quoted :
>
> >I have posted pictures of me masterbating with a snake whilst my
girlfirend sucks my titties. Enjoy this set ;)
> >
> >http://snakesex.0catch.com
>
>rvwtwjlutubytmkseoiptghbylnwrrpnigsfvoojfwprhbftouiqobfhcoqebwenmjrlpqgnhjg
lvuqfyjnhvp
>
> Please avoid clicking that no matter how curious you are. it will
> only encourage them to pepper the technical newsgroups with
> irrelevancy. If you must, google to find similar sites.
One can only hope that the snake is highly venomous.
|
| Author |
Message |
Razii

|
Posted: 2008-6-8 9:07:00 |
Top |
java-programmer, benchmarks? java vs .net (binarytrees)
On Sat, 7 Jun 2008 17:44:18 -0700 (PDT), kwikius
<email***@***.com> wrote:
>Java, .NET starts out slow buddy.. King Twat, Mr Skeet, Mr Harrop and
>you shoved a lot of time, figuring out what we already know for last
>10 years. Your only option... you turn off GC. Fucking unacceptable
>for any multi user system. Only way to get any sort of performance out
>of GC system is to hog the system.
>
>Have a nice fuckin' day.
>
>Oh and Fuck Off Ratboy..
lol ...
I added the C++ group back. If you are going to troll, keep all the
groups on the list.
Or are you ashamed?
|
| |
|
| |
 |
Razii

|
Posted: 2008-6-8 9:07:00 |
Top |
java-programmer >> benchmarks? java vs .net (binarytrees)
On Sat, 7 Jun 2008 17:44:18 -0700 (PDT), kwikius
<email***@***.com> wrote:
>Java, .NET starts out slow buddy.. King Twat, Mr Skeet, Mr Harrop and
>you shoved a lot of time, figuring out what we already know for last
>10 years. Your only option... you turn off GC. Fucking unacceptable
>for any multi user system. Only way to get any sort of performance out
>of GC system is to hog the system.
>
>Have a nice fuckin' day.
>
>Oh and Fuck Off Ratboy..
lol ...
I added the C++ group back. If you are going to troll, keep all the
groups on the list.
Or are you ashamed?
|
| |
|
| |
 |
Jon Skeet [C# MVP]

|
Posted: 2008-6-8 15:39:00 |
Top |
java-programmer >> benchmarks? java vs .net (binarytrees)
Jon Harrop <email***@***.com> wrote:
> >> My claim was clearly perfectly correct.
> >
> > Rubbish. You claimed that Razii had turned the garbage collector off.
>
> Now you have resorted to misquoting me. I think that says it all.
You've applied different options to the program to make it appear that
your claim about Razii's options were correct. I missed out the word
"effectively" above. Which of those is more important?
Similarly, you've later managed to quote something I wrote about *your*
set of options as if I was writing it about Razii's set of options.
> > He certainly hadn't, or the program would not have run to completion,
> > limited as it was by his options to 512MB.
>
> For n=20?
Yes.
> > Just to make it absolutely clear, here is how Razii was running the
> > code:
> >
> > java -server -verbose:gc -Xms512m -Xmx512m -XX:NewRatio=1
>
> You have not specified "n" but it appears that your entire line of thinking
> revolves around n=20.
Yes, which is what he ran.
The post where you claimed Razii had effectively claimed the garbage
collector off was message ID
<email***@***.com>
If you look back up the thread directly from that to the last time
Razii had specified options (i.e. the run that was under discussion) it
was message ID <email***@***.com>.
The exactly command line specified was:
$ time java -server -Xms512m -Xmx512m -XX:NewRatio=1 binarytrees 20
> > With those options, the garbage collector *does* run, and *does*
> > collect memory.
>
> Here is another trivial counter example using Razii's arguments as you
> quoted them:
I only quoted the memory part because that's the only part I *saw* you
change. However, if you look
> $ java -server -verbose:gc -Xms512m -Xmx512m -XX:NewRatio=1 binarytrees 13
> stretch tree of depth 14 check: -1
> 16384 trees of depth 4 check: -16384
> 4096 trees of depth 6 check: -4096
> 1024 trees of depth 8 check: -1024
> 256 trees of depth 10 check: -256
> 64 trees of depth 12 check: -64
> long lived tree of depth 13 check: -1
>
> As you can see, the GC never ran.
>
> > Your claim was absolutely incorrect, and your attempt
> > to confuse the matter by posting other options which *did* negate the
> > need for the garbage collector to run does not in any way change the
> > options under which Razii ran his test.
>
> I said "the GC is effectively off". You say "Rubbish... the need for the GC
> to run had been negated.". The difference is academic.
I would agree - but you're quoting me in entirely the wrong context.
Let's have a look at the statement where I talked about "the need for
the GC to had had been negated":
<quote>
Your claim was absolutely incorrect, and your attempt
to confuse the matter by posting other options which *did* negate the
need for the garbage collector to run does not in any way change the
options under which Razii ran his test.
</quote>
Oh look, it's in the context of *your* options, not Razii's.
I never claimed, nor *would* I claim, that the need for the GC to run
had been negated with Razii's options. Those are the only options which
I think should be considered in this part of the discussion, as those
are the options for which you originally claimed that the GC had been
effectively turned off.
> > Now rather than just repeatedly stating your claim, or arguing by using
> > *different* options, please address the steps above. Which of the 5
> > facts/deductions above do you disagree with? The conclusion directly
> > contradicts your claim, so you should either retract your claim or
> > refute the logic above.
>
> The main problem is with your interpretation of the word "effectively". You
> seem to think that you can add and remove this word at will without
> affecting the meaning of a sentence when, in fact, you cannot.
In this case it doesn't change things. If the garbage collector had
*effectively* been turned off, it would not have been able to run to
completion.
> Consequently, your conclusion (5) is wrong. It should be "Therefore the GC
> had *not* been turned off". No disagreement here. But that says nothing
> about my original statement.
No way. You can't realistically claim a garbage collector has been
"effectively" turned off when it being turned *on* is critical to the
program running to completion. What exactly do you take "effectively"
to mean? I take it to mean "to the same effect". Now I'm happy for
"effect" to only mean in terms of computed results rather than
performance - so a fast program can be effectively the same as a slow
program - but it can't be in terms of completing the run. Options where
the program fails to run to completion are *not* "effectively" the same
as options where the program runs fine.
> There were two sides to my original point. Firstly, if you manually tweak
> the GC parameters by hand for one specific input on one specific machine
> then you are doing manual memory management.
No - you're changing the configuration options to let the automatic
memory management work more effectively. Note how I did exactly the
same to make the .NET GC use a different implementation - and again, it
sped things up.
> Garbage collection means *automatic* memory management. So you can
> kiss goodbye to the idea of claiming that your GC is fast (which is
> exactly what Razii was trying to do). The same goes for explicitly
> calling the GC from within your code (it is a form of manual memory
> management).
Well, it's a hint to the garbage collector - a hint which is usually
unnecessary, but *can* occasionally be beneficial. There's a long, long
way from that to fully manual memory management though.
> Secondly, Razii's technique and results for this benchmark have absolutely
> no bearing on reality whatsoever. Indeed, I cannot even reproduce his
> results using the same program with the same input on a slightly different
> machine. So let's not pretend this is of any practical relevance.
I never have.
> All you have managed to do is optimize a flawed benchmark which, as I said
> from the beginning, is completely fruitless.
No argument there - but then that's not what I was responding to, was
it?
Let me make this absolutely crystal clear, so that so long as you quote
from this sentence down in your reply, everything else above is
irrelevant:
Given a run of the code with these options:
$ time java -server -Xms512m -Xmx512m -XX:NewRatio=1 binarytrees 20
You claimed that Razii effectively turned the GC off. I claim that he
certainly didn't, because with the GC having no effect the program
would not have completed.
Do you disagree with my claim that with the GC *actually* turned off
(if there were some way to do that) the program would have failed to
finish, or do you think that a (hypothetical) set of options where a
program fails to finish can be *effectively* the same as a set of
options where the program manages to run?
--
Jon Skeet - <email***@***.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
|
| |
|
| |
 |
Mark Thornton

|
Posted: 2008-6-8 19:35:00 |
Top |
java-programmer >> benchmarks? java vs .net (binarytrees)
kwikius wrote:
> On Jun 7, 8:38 pm, Arne Vajh鴍 <email***@***.com> wrote:
> <...>
>
> Java uses virtual memory. If there is not
>> enough physical memory to cover then it still works - it just becomes
>> very slow.
>
> Java, .NET starts out slow buddy.. King Twat, Mr Skeet, Mr Harrop and
> you shoved a lot of time, figuring out what we already know for last
> 10 years. Your only option... you turn off GC. Fucking unacceptable
> for any multi user system.
> Only way to get any sort of performance out
> of GC system is to hog the system.
In real systems this is usually not true. In most applications it is
possible to get good performance from the garbage collector. In
particular, Java provides many options for tuning the garbage collector
(if you think you can do better than the defaults). Razii may be
irritating, but responding with untruths of your own is not helpful.
Mark Thornton
|
| |
|
| |
 |
Razii

|
Posted: 2008-6-8 21:19:00 |
Top |
java-programmer >> benchmarks? java vs .net (binarytrees)
On Sun, 08 Jun 2008 12:34:34 +0100, Mark Thornton
<email***@***.com> wrote:
>In real systems this is usually not true. In most applications it is
>possible to get good performance from the garbage collector.
It's not only not true. It's downright false.
http://www.idiom.com/~zilla/Computer/javaCbenchmark.html
Consider what happens when you do a new/malloc: a) the allocator looks
for an empty slot of the right size, then returns you a pointer. b)
This pointer is pointing to some fairly random place.
With GC, a) the allocator doesn't need to look for memory, it knows
where it is, b) the memory it returns is adjacent to the last bit of
memory you requested. The wandering around part happens not all the
time but only at garbage collection. And then (depending on the GC
algorithm) things get moved of course as well.
The cost of missing the cache
The big benefit of GC is memory locality. Because newly allocated
memory is adjacent to the memory recently used, it is more likely to
already be in the cache.
How much of an effect is this? One rather dated (1993) example shows
that missing the cache can be a big cost: changing an array size in
small C program from 1023 to 1024 results in a slowdown of 17 times
(not 17%). This is like switching from C to VB! This particular
program stumbled across what was probably the worst possible cache
interaction for that particular processor (MIPS); the effect isn't
that bad in general...but with processor speeds increasing faster than
memory, missing the cache is probably an even bigger cost now than it
was then.
(It's easy to find other research studies demonstrating this; here's
one from Princeton: they found that (garbage-collected) ML programs
translated from the SPEC92 benchmarks have lower cache miss rates than
the equivalent C and Fortran programs.)
This is theory, what about practice? In a well known paper [2] several
widely used programs (including perl and ghostscript) were adapted to
use several different allocators including a garbage collector
masquerading as malloc (with a dummy free()). The garbage collector
was as fast as a typical malloc/free; perl was one of several programs
that ran faster when converted to use a garbage collector. Another
interesting fact is that the cost of malloc/free is significant: both
perl and ghostscript spent roughly 25-30% of their time in these
calls.
Besides the improved cache behavior, also note that automatic memory
management allows escape analysis, which identifies local allocations
that can be placed on the stack. (Stack allocations are clearly
cheaper than heap
|
| |
|
| |
 |
Rudy Velthuis

|
Posted: 2008-6-8 22:10:00 |
Top |
java-programmer >> benchmarks? java vs .net (binarytrees)
Razii wrote:
> Consider what happens when you do a new/malloc: a) the allocator looks
> for an empty slot of the right size, then returns you a pointer.
Modern allocators have several arrays of slots of suitable sizes, and
can therefore easily find one in the right size. The next allocation of
that size will also be immediately adjacent. Only rather large sizes
require another approach, but I assume these are pretty rare in both
kinds of environments, and I guess that programs tend to hang on to
such large objects much longer as well. Deallocation of objects is
immediate, which often means that memory consumption is lower and not
dependent on when a GC might finally run. Also, no heaps of memory are
moved around in non-GC memory management.
IOW, there are arguments for both approaches. The GC one has the big
advantage that one big cause of errors, all errors regarding memory
use, are more or less completely eliminated. But I doubt I would call
speed one of the main factors to choose a GC.
--
Rudy Velthuis http://rvelthuis.de
"My last cow just died, so I won't need your bull anymore."
|
| |
|
| |
 |
Lew

|
Posted: 2008-6-8 22:42:00 |
Top |
java-programmer >> benchmarks? java vs .net (binarytrees)
Razii wrote:
> but with processor speeds increasing faster than
> memory, missing the cache is probably an even bigger cost now than it
> was then.
You might not have noticed, but processor speeds have been flat for the last
several years, or actually declined. Memory has gotten faster, and CPUs have
gotten more cache, so actually the trend is the opposite of what you stated.
--
Lew
|
| |
|
| |
 |
Lew

|
Posted: 2008-6-8 22:45:00 |
Top |
java-programmer >> benchmarks? java vs .net (binarytrees)
Rudy Velthuis wrote:
> Modern allocators have several arrays of slots of suitable sizes, and
> can therefore easily find one in the right size. The next allocation of
> that size will also be immediately adjacent. Only rather large sizes
> require another approach, but I assume these are pretty rare in both
> kinds of environments, and I guess that programs tend to hang on to
> such large objects much longer as well. Deallocation of objects is
> immediate, which often means that memory consumption is lower and not
> dependent on when a GC might finally run. Also, no heaps of memory are
> moved around in non-GC memory management.
Deallocation of young objects in Java takes no time at all. GCs of the young
generation take very little time for typical memory-usage patterns. It could
be, for a large class of programs, that memory management takes less time in a
GCed language like Java than in a language like C++ with manual memory management.
> IOW, there are arguments for both approaches. The GC one has the big
> advantage that one big cause of errors, all errors regarding memory
> use, are more or less completely eliminated. But I doubt I would call
> speed one of the main factors to choose a GC.
It can be. The problem is that assertions about speed are nearly impossible
to make /a priori/ - there are so many factors and emergent interactions
involved that one is unlikely to guess correctly without experimentation and
measurement.
--
Lew
|
| |
|
| |
 |
QXJuZSBWYWpow7hq

|
Posted: 2008-6-8 23:09:00 |
Top |
java-programmer >> benchmarks? java vs .net (binarytrees)
Lew wrote:
> Razii wrote:
>> but with processor speeds increasing faster than
>> memory, missing the cache is probably an even bigger cost now than it
>> was then.
>
> You might not have noticed, but processor speeds have been flat for the
> last several years, or actually declined.
Processor speed is increasing at the same speed as ever.
GHz rates are not. They reached the heat barrier. But GHz was
never a good indication for speed.
Growth in core speed has slowed down, because the the way processors
get faster today is to add more cores.
Arne
|
| |
|
| |
 |
Lew

|
Posted: 2008-6-9 0:05:00 |
Top |
java-programmer >> benchmarks? java vs .net (binarytrees)
Arne Vajh酶j wrote:
> Lew wrote:
>> Razii wrote:
>>> but with processor speeds increasing faster than
>>> memory, missing the cache is probably an even bigger cost now than it
>>> was then.
>>
>> You might not have noticed, but processor speeds have been flat for
>> the last several years, or actually declined.
>
> Processor speed is increasing at the same speed as ever.
>
> GHz rates are not. They reached the heat barrier. But GHz was
> never a good indication for speed.
>
> Growth in core speed has slowed down, because the the way processors
> get faster today is to add more cores.
I believe you're speaking of processing speed. The term "processor speed" has
always meant clock speed of a processor in every context I've encountered it
heretofore.
Adding cores to a processor doesn't inherently make it faster. The software
has to take advantage of the additional cores.
--
Lew
|
| |
|
| |
 |
QXJuZSBWYWpow7hq

|
Posted: 2008-6-9 2:19:00 |
Top |
java-programmer >> benchmarks? java vs .net (binarytrees)
Lew wrote:
> Arne Vajh酶j wrote:
>> Lew wrote:
>>> Razii wrote:
>>>> but with processor speeds increasing faster than
>>>> memory, missing the cache is probably an even bigger cost now than it
>>>> was then.
>>>
>>> You might not have noticed, but processor speeds have been flat for
>>> the last several years, or actually declined.
>>
>> Processor speed is increasing at the same speed as ever.
>>
>> GHz rates are not. They reached the heat barrier. But GHz was
>> never a good indication for speed.
>>
>> Growth in core speed has slowed down, because the the way processors
>> get faster today is to add more cores.
>
> I believe you're speaking of processing speed. The term "processor
> speed" has always meant clock speed of a processor in every context I've
> encountered it heretofore.
Could be. But that meaning does not fit very well with the original
context.
> Adding cores to a processor doesn't inherently make it faster. The
> software has to take advantage of the additional cores.
It makes it potential faster.
It is up to the programmers to utilize the potential.
Arne
|
| |
|
| |
 |
Lew

|
Posted: 2008-6-9 2:36:00 |
Top |
java-programmer >> benchmarks? java vs .net (binarytrees)
Lew wrote:
>> Adding cores to a processor doesn't inherently make it faster. The
>> software has to take advantage of the additional cores.
Arne Vajh酶j wrote:
> It makes it potential faster.
And most OSes do manage to use at least some of that potential.
> It is up to the programmers to utilize the potential.
I agree completely.
I also see a trend for more and more programs to at least allow its use. CPUs
are also getting more and faster cache memory, and mainboard memory
utilization also is getting faster, so the OP's assertion that "processor
speeds [are] increasing faster than memory" becomes a little less generally
reliable.
Regardless. you and the OP together are clearly correct that processing speed
is getting much faster, as is memory speed. Taken together, along with
implications of multi-processor algorithms on the memory model, there are
great effects on the state of the art in programming.
Nit-picking about specific minor terminologies aside, your conclusions are
inarguable.
--
Lew
|
| |
|
| |
 |
Jon Harrop

|
Posted: 2008-6-9 4:54:00 |
Top |
java-programmer >> benchmarks? java vs .net (binarytrees)
Razii wrote:
> On Sun, 08 Jun 2008 12:34:34 +0100, Mark Thornton
> <email***@***.com> wrote:
>>In real systems this is usually not true. In most applications it is
>>possible to get good performance from the garbage collector.
>
> It's not only not true. It's downright false.
>
> http://www.idiom.com/~zilla/Computer/javaCbenchmark.html
>
> Consider what happens when you do a new/malloc: a) the allocator looks
> for an empty slot of the right size, then returns you a pointer. b)
> This pointer is pointing to some fairly random place.
> ...
This is just another strawman argument. Malloc is not the only alternative
to GC.
> With GC, a) the allocator doesn't need to look for memory, it knows
> where it is, b) the memory it returns is adjacent to the last bit of
> memory you requested. The wandering around part happens not all the
> time but only at garbage collection. And then (depending on the GC
> algorithm) things get moved of course as well.
That is exactly that the STL allocators do, for example.
--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u
|
| |
|
| |
 |
Jon Harrop

|
Posted: 2008-6-9 5:03:00 |
Top |
java-programmer >> benchmarks? java vs .net (binarytrees)
Lew wrote:
> Rudy Velthuis wrote:
>> Modern allocators have several arrays of slots of suitable sizes, and
>> can therefore easily find one in the right size. The next allocation of
>> that size will also be immediately adjacent. Only rather large sizes
>> require another approach, but I assume these are pretty rare in both
>> kinds of environments, and I guess that programs tend to hang on to
>> such large objects much longer as well. Deallocation of objects is
>> immediate, which often means that memory consumption is lower and not
>> dependent on when a GC might finally run. Also, no heaps of memory are
>> moved around in non-GC memory management.
>
> Deallocation of young objects in Java takes no time at all...
You are ignoring all of the overheads of a GC, like thread synchronization,
stack walking and limitations placed upon the code generator required to
keep the GC happy.
If you compare generically and assume infinite development time then
lower-level languages will surely win in terms of raw performance. The
reason the world moved on to GC'd languages is that they allow more
complicated programs to be written more robustly and efficiently in a given
amount of development time, i.e. they are more cost effective.
--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u
|
| |
|
| |
 |
Lew

|
Posted: 2008-6-9 5:19:00 |
Top |
java-programmer >> benchmarks? java vs .net (binarytrees)
Jon Harrop wrote:
> You are ignoring all of the overheads of a GC, like thread synchronization,
> stack walking and limitations placed upon the code generator required to
> keep the GC happy.
Balanced, to a degree at least, by the absence of manual memory-management
code, which would also have an overhead of its own, and the presence of
dynamic optimizers like Hotspot.
> If you compare generically and assume infinite development time then
> lower-level languages will surely win in terms of raw performance. The
> reason the world moved on to GC'd languages is that they allow more
> complicated programs to be written more robustly and efficiently in a given
> amount of development time, i.e. they are more cost effective.
Your points are well taken, but all I'm saying is that /a priori/ arguments
about the overhead of GC are not reliable. The advantages to performance that
GC brings tend to reduce the overhead of collections. Which one wins depends
so much on details of the JVM implementation, the needs of the algorithm, the
idioms followed by the app programmer, and other factors that it seems the
height of hubris to predict without measurement.
So far it seems that you must be at least mostly correct - from what I've seen
and read, most Java programs on most JVMs still seem to be somewhat slower
than most "natively compiled" programs. However, the gap has unequivocally
lessened over the years, and one can easily see it tilting the way of the
intelligently GCed platform.
--
Lew
|
| |
|
| |
 |
Arne Vajh鴍

|
Posted: 2008-6-9 11:04:00 |
Top |
java-programmer >> benchmarks? java vs .net (binarytrees)
Rudy Velthuis wrote:
> Razii wrote:
>> Consider what happens when you do a new/malloc: a) the allocator looks
>> for an empty slot of the right size, then returns you a pointer.
>
> Modern allocators have several arrays of slots of suitable sizes, and
> can therefore easily find one in the right size. The next allocation of
> that size will also be immediately adjacent. Only rather large sizes
> require another approach, but I assume these are pretty rare in both
> kinds of environments, and I guess that programs tend to hang on to
> such large objects much longer as well. Deallocation of objects is
> immediate, which often means that memory consumption is lower and not
> dependent on when a GC might finally run. Also, no heaps of memory are
> moved around in non-GC memory management.
>
> IOW, there are arguments for both approaches. The GC one has the big
> advantage that one big cause of errors, all errors regarding memory
> use, are more or less completely eliminated. But I doubt I would call
> speed one of the main factors to choose a GC.
Actually GC speed is very good.
The problem people complain over is the non deterministic
aspect of it.
Arne
|
| |
|
| |
 |
Arne Vajh鴍

|
Posted: 2008-6-9 11:07:00 |
Top |
java-programmer >> benchmarks? java vs .net (binarytrees)
Jon Harrop wrote:
> Lew wrote:
>> Rudy Velthuis wrote:
>>> Modern allocators have several arrays of slots of suitable sizes, and
>>> can therefore easily find one in the right size. The next allocation of
>>> that size will also be immediately adjacent. Only rather large sizes
>>> require another approach, but I assume these are pretty rare in both
>>> kinds of environments, and I guess that programs tend to hang on to
>>> such large objects much longer as well. Deallocation of objects is
>>> immediate, which often means that memory consumption is lower and not
>>> dependent on when a GC might finally run. Also, no heaps of memory are
>>> moved around in non-GC memory management.
>> Deallocation of young objects in Java takes no time at all...
>
> You are ignoring all of the overheads of a GC, like thread synchronization,
> stack walking and limitations placed upon the code generator required to
> keep the GC happy.
I would expect non-GC solutions to need more thread synchronization
than GC because it will need it many more times.
> If you compare generically and assume infinite development time then
> lower-level languages will surely win in terms of raw performance. The
> reason the world moved on to GC'd languages is that they allow more
> complicated programs to be written more robustly and efficiently in a given
> amount of development time, i.e. they are more cost effective.
I agree with that part.
Arne
|
| |
|
| |
 |
Arne Vajh鴍

|
Posted: 2008-6-9 11:09:00 |
Top |
java-programmer >> benchmarks? java vs .net (binarytrees)
kwikius wrote:
> On Jun 7, 8:38 pm, Arne Vajh鴍 <email***@***.com> wrote:
>> Java uses virtual memory. If there is not
>> enough physical memory to cover then it still works - it just becomes
>> very slow.
>
> Java, .NET starts out slow buddy.. King Twat, Mr Skeet, Mr Harrop and
> you shoved a lot of time, figuring out what we already know for last
> 10 years. Your only option... you turn off GC. Fucking unacceptable
> for any multi user system. Only way to get any sort of performance out
> of GC system is to hog the system.
My I recommend you to read a beginners book about operating
systems ?
You seem in need for some basic understanding of what
virtual memory means.
Arne
|
| |
|
| |
 |
Rudy Velthuis

|
Posted: 2008-6-9 19:30:00 |
Top |
java-programmer >> benchmarks? java vs .net (binarytrees)
Arne Vajh鴍 wrote:
> > IOW, there are arguments for both approaches. The GC one has the big
> > advantage that one big cause of errors, all errors regarding memory
> > use, are more or less completely eliminated. But I doubt I would
> > call speed one of the main factors to choose a GC.
>
> Actually GC speed is very good.
>
> The problem people complain over is the non deterministic
> aspect of it.
People also complained about messaging and the non-linear aspect of it
when they moved from DOS to Windows. I guess, to many, this is a
similar issue, i.e. they sense a loss of control. <g>
--
Rudy Velthuis http://rvelthuis.de
"We don't make mistakes, we just have happy little accidents."
-- Bob Ross, "The Joy of Painting"
|
| |
|
| |
 |
Jon Harrop

|
Posted: 2008-6-9 21:17:00 |
Top |
java-programmer >> benchmarks? java vs .net (binarytrees)
Jon Skeet [C# MVP] wrote:
> ...
> - so a fast program can be effectively the same as a slow
> program - but it can't be in terms of completing the run. Options where
> the program fails to run to completion are *not* "effectively" the same
> as options where the program runs fine.
There is an implicit benchmarking methodology behind your statements that is
flawed.
All benchmarks must impose a flow of information:
variable inputs -> constant program -> outputs
So "n" is the *only* variable input to our static program in this case. The
parameters passed to the GC are constants of the program.
You must not restrict consideration to a single constant input value "n"
because that permits partial specialization of the program and any
benchmark can then be arbitrarily optimized, ultimately by simply spitting
out the known correct output for the only input it will ever receive.
Moreover, the constants of the program (including the parameters to -Xms
and -Xmx) cannot be functions of the input. Specifically, they cannot be
optimized for a specific input at the cost of correctness on other inputs.
Such a program cannot reasonably be considered valid.
>> There were two sides to my original point. Firstly, if you manually tweak
>> the GC parameters by hand for one specific input on one specific machine
>> then you are doing manual memory management.
>
> No - you're changing the configuration options to let the automatic
> memory management work more effectively.
Razii was fiddling by hand (manually) with bits and bytes (memory) to make
the current JVM's representation of some data structures for a given input
happen to just fit into a heap of a certain size (management).
> Note how I did exactly the same to make the .NET GC use a different
> implementation - and again, it sped things up.
Firstly, your tweak did not break the program for other (previously valid)
inputs as Razii's does. Secondly, your tweak showed a uniformly significant
performance improvement on a variety of machines but Razii's does not.
> There's a long, long way from that to fully manual memory management
> though.
Measuring some memory requirements by hand in order to preallocate a fixed
size heap is an ancient hallmark of manual memory management dating back to
Fortran programs. That is exactly what Razii did.
> Let me make this absolutely crystal clear, so that so long as you quote
> from this sentence down in your reply, everything else above is
> irrelevant:
>
> Given a run of the code with these options:
>
> $ time java -server -Xms512m -Xmx512m -XX:NewRatio=1 binarytrees 20
Last time you wrote only:
time java -server -Xms512m -Xmx512m -XX:NewRatio=1
which I agreed with.
> You claimed that Razii effectively turned the GC off. I claim that he
> certainly didn't, because with the GC having no effect the program
> would not have completed.
>
> Do you disagree with my claim that with the GC *actually* turned off
> (if there were some way to do that)
You can turn the GC off by cranking up the heap size, which is exactly what
Razii was doing.
> the program would have failed to finish,
All of these programs fail for sufficiently large "n" because they run out
of space.
> or do you think that a (hypothetical) set of options where a
> program fails to finish can be *effectively* the same as a set of
> options where the program manages to run?
They are effectively the same because we never had any assurance that the GC
was going to collect aggressively enough anyway.
--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u
|
| |
|
| |
 |
Jon Harrop

|
Posted: 2008-6-9 21:31:00 |
Top |
java-programmer >> benchmarks? java vs .net (binarytrees)
Arne Vajh鴍 wrote:
> Razii wrote:
>> On Sat, 07 Jun 2008 19:35:08 +0100, Jon Harrop <email***@***.com>
>> wrote:
>>>> The shootout doesn't use 3 gig max memory.
>>> How do you know that?
>>
>> They list the options they use. Besides, the computer they are using,
>> Pentium 4, has only 512 MB ram.
>
> Xmx is a reliable max on memory usage.
The Java program with the 512Mb limit actually uses 800Mb here.
--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- updating value in all sessionHi, I am a little stumped on this one, and I was hoping someone else
out there ran into and solved this problem. Using a J2EE servlet
container every client (browser) will acquire a session and certain
values will be stored in this session. However, if a certain
parameter is changed it should invoke a method in one of the beans in
the session, which all sessions will have. This sounds like more like
a type of event handler, but I am not aware of any non-gui event
listeners. Any ideas?
Regards,
Brian
- 2
- Making a variable an objectInside a class, amongst other variables, I have a variable 'orientation'
which can hold three valid values: horizontal, vertical, and no orientation.
In true oo design, should i bother creating a Orientation nested class
just for the variable no matter how small the class is?
- 3
- Genercis adviceHello!
i've just read some docs about generics in Java, and i would like to do
a complete Canvas class. Here is my attempt:
import java.util.LinkedList;
import java.util.List;
public class Canvas {
private List<Shape> shapeList = null;
class Shape {
public void draw() {
}
}
class SubShape extends Shape {
public void draw() {
}
}
public Canvas() {
shapeList = new LinkedList<Shape>();
add(new SubShape());
drawAll();
}
public void drawAll() {
// TEH UGLYNESS !!!
List<? extends Shape> shapeList = this.shapeList;
for (Shape s:shapeList)
s.draw();
}
public void add(Shape s) {
shapeList.add(s);
}
}
From what i've understood:
- unbounded is for writing
- bounded is for reading
So basically, i have to use temporaries or i have to do a
"drawAll(bounded version)" wich is even worse.
I really hope i've missed something because i think this stink.
Any advice/explaination apreciated :)
- 4
- Drag'n'Drop & Using Drag ImagesI have a situation where I want to be able to drag a component (or an image
of one) from one container to another. Using the excellent beginner article
at
http://java.sun.com/products/jfc/tsc/articles/dragndrop/
I have got this working in my own sample; the drag operation begins, and I
can react to the item being dropped.
The sample given uses
DragGestureEvent.startDrag(Cursor dragCursor, Transferable transferable,
DragSourceListener dsl)
This works fine, I get the change in cursor to represent the drag. Now I
want to actually have an image dragged with the cursor / in place of the
cursor (I don't mind which), so I adapted my working sample to instead use
DragGestureEvent.startDrag(Cursor dragCursor, Image dragImage, Point
imageOffset, Transferable transferable, DragSourceListener dsl)
However, there is no change: no image is dragged, it still just changes the
cursor. No exceptions are generated, and the drag still proceeds as normal.
I can see that the Image object (whose reference is being passed) is valid.
I tried a Point of (10, 10) (not sure whether this represents cursor hotspot
offset from image top-left or vice versa, or even something entirely
different) and of (0, 0) instead when that didn't work ( (0, 0) seems safe
in all cases).
I delved into the source code just a little to see if there was anything
obvious, such as the image needing to be of a specific size or format or
something; a cursory glance only shows that the image gets passed down the
line, and there are no comments on whether it should be a special type of
image or just any old image.
So I'm a little stuck. Anyone got any ideas for why it doesn't use the
supplied image? Have I missed a step?
WinXP Pro SP1
Java 1.4.2_03
--
- 5
- Eclipse _mthclass$ problemI have an issue with Eclipse not adding a static Class called
_mthclass$ to my compiled class file and when I compile the same
source using Ant with jdk 1.3 or 1.4 it adds this _mthclass$. I read
that Eclipse has its own javac to compile class files and that you
cannot change this. My classes are now incompatible during
Serialization. Has anyone come across a way to get Eclipse to add this
class or a work around?
- 6
- How to gray out the files in JFileChooser?I only let user select the directories,
not let user select the files.
So I
myFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
That is fine, but user complain about that, they want to
make sure there are files under the directory.
If I do
myFileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
Then user will mistake select a file, which I don't let them select a
file. I need to popup a dialog says "Please select a directory only".
The idea thing is I can gray out the file names, so user can see
there are files under a directory, but they can't select any file,
only can select a directory.
Anyone out there has any idea how to gray out the file names in
JFileChooser?
Thank Q!
- 7
- Question about string pattern matchingRoedy,
Roedy Green wrote:
>On Mon, 09 Jan 2006 21:40:00 -0600, Alan Krueger
><email***@***.com> wrote, quoted or indirectly quoted someone
>who said :
>
>>If you insist on writing this yourself, study finite automata and
>>regular languages. Build a tool that translates regular expressions
>>into non-deterministic finite automata (NFAs) then transforms those into
>>optimized deterministic finite automata (DFAs). Make it so these are
>>compiled into Java source or bytecode directly for speed.
>
>or use a generated parser. See http://mindprod.com/jgloss/parser.html
>
>Also see http://mindprod.com/jgloss/finitestate.html
The resources are very useful!
regards,
George
--
Message posted via http://www.javakb.com
- 8
- endeavorsYou should all JUMP UP AND DOWN for TWO HOURS while I decide on a NEW
CAREER!!
- 9
- 10
- Write formatted XML to a fileHi,
I create the XML with DOM and save it to a file. But when I open such
file with Notepad, for instance, I see the XML file in one line - it
is not formatted/aligned. If I open it with IExplorer it looks fine.
I am looking for the way to save XML to a file so that XML would be
formatted.
The save code:
-------------------
doc.getDocumentElement().normalize();
DOMSource ds = new DOMSource(doc);
StreamResult sr = new StreamResult(out);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer trans = tf.newTransformer();
trans.transform(ds, sr);
Thanks,
Pavel
- 11
- cerat warI use jbuider 4 and I made a web application project. But I don't know how I
can get a war file from my project. Can somebody help me?
- 12
- Root Object == OO !?! [Was: Re: My strange service with an error]Lew wrote:
> (I've read a definition that a language that enforces a single Object root
> type is "object-oriented", whereas a language like C++ that allows root
> types other than Object is "object-supporting".)
You do seem to have a talent for finding the most astounding drivel ;-) Where
did you find that particular crock of moonshine ?
-- chris
(P.S. I don't at all dispute that C++ is better described as "supporting OO"
than as being an OO language -- but that's nothing at all to do with its lack
of a single root class.)
- 13
- ServletOutputStream to Browser OK in NS, but not IE??Hi All,
I am replacing a Netscape Application Server appLogic with a servlet.
The servlet is supposed to take a URL and stream the file to the
user's browser. I checked a number of examples from post in this news
group to get examples of how to do this (thanks for the good info).
The servelt works fine in NetScape 7.0 (jpg, pdf, html files open in
the current browser session), but always pops up the file download box
in IE 6. In IE the file is always downloaded and opened. This
happens even for html files. This is a problem, since the appLogic
opens most files in the browser, Word docs get opened in a separate
instance of MS Word. However, the user never sees the download box.
I tried modifiying the web.xml for this servelet to allow adding the
filename to to be appended to the servlet name,
GetContentItem/filename.jpg, but that didn't make any difference. The
content type and filename appear appear in the download dialog.
Here is the servelt code, any suggestions will be appreciated:
public class GetContentItem extends HttpServlet {
// initalise the servlet within init()
private static Log log = LogFactory.getLog(GetContentItem.class);
public void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
if (log.isDebugEnabled())
log.debug("IN " + GetContentItem.class + " doGet" );
String sCRBaseURLRoot =
"http://supporttest1.web.lucent.com:20101/cr/";
String sDocPath = "Live/Product/5ESS/R16/Retrofit_Information/090094058001c628.jpg";
String sDocPath2 =
"Live/Product/5ESS/R16/Release_Information/0900940580026c41/french.pdf";
String sDocPath3 =
"/Live/Product/5ESS/R16/Release_Information/0900940580026cc1/spanish.doc";
String sDocPath4 =
"/Live/Product/5ESS/R16/Release_Information/090094058002791c/61402_Release_Deployment.html";
String filename = "090094058001c628.jpg";
String filename2= "french.pdf";
String filename3= "spanish.doc";
String filename4 = "61402_Release_Deployment.html";
sDocPath=sDocPath4;
filename = filename4;
String sUrl = sCRBaseURLRoot + sDocPath;
java.io.InputStream in=null;
ServletOutputStream stream = null;
try{
URL u = new URL(sUrl);
URLConnection c = u.openConnection();
c.connect();
in = new DataInputStream(c.getInputStream());
String sHeaderField=null;
String sHeaderFieldKey=null;
int i = 1;
stream = response.getOutputStream();
response.setContentType(c.getContentType());
response.setContentLength(c.getContentLength());
response.setHeader("Content-disposition","attachment;filename=\"" +
filename + "\"");
int bytes_read;
int BUFSIZE = 8192;
byte[] buffer = new byte[BUFSIZE];
while((bytes_read=in.read(buffer,0,BUFSIZE))!=-1){
stream.write(buffer,0,bytes_read);
}
} catch(FileNotFoundException e){
log.error("FileNotFoundException accessing document " + sDocPath +
e );
} catch(Exception e){
log.error("Exception accessing document " + sDocPath + e );
} finally{
try{
in.close();
stream.flush();
stream.close();
} catch (Exception e){}
}
}
}
I hope the code display format is not too ugly in the post.
Thanks,
Tom
- 14
- Problem reading file from applet!Hello!
I'm not too experienced in java and I have a problem reading from a file
with my applet. As I understand the applet is aloud to read from the same
folder as the applet is in.
I have declared a File (that point to my file in the same folder), a
FileReader with try and catch Exception and then I have written
FileReader.read(char c, int, int) with try and catch. The compiler accepts
my code but when I run my applet in appletviewer the promt gives me errors.
Can somebody please help me?
Many, many thanks in advance!
Best regards
Marcus
- 15
- 64 bit linux on VM to run Java appOn Fri, 20 Jun 2008 15:58:35 GMT, Roedy Green
<email***@***.com> wrote, quoted or indirectly quoted
someone who said :
>
>see http://mindprod.com/bgloss/sixtyfourbit.html
Thanks for all your input in whipping that entry into shape.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
|
|
|