Joseph Kampf

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

Recent posts by Joseph Kampf

You have 2 loops in your code. You sure you want that?

You have have your value of i used in both loop controls.

13 years ago

Marlon Churchill wrote:This question is about how Java creates objects and when. I think I'm missing some basic concept. the code and question are from the Sierra and Bates SCJP 6 book, Chapter 3, question 11.


When line 16 is reached, how many objects are available for garbage collection?

There are 2 wrinkles here.

First there is a static member of the class Alpha. So once you assign an object to Alpha.b1 you have an open reference to that object. That object will never be GCed until Alpha.b1 is set to null or another instance of Beta. So since b1 is assigned to Alpha.b1, b1 will not be GCed.

Also you don't set a2 to null, so a2.b2 is still around. So b2 is not eligible for GC.

So b1 can't be eligible, a2 and b2 are not eligible for GC. You created 4 objects, so only 1 object is eligible for GC. (That is a1)

The correct answer is 1, but I seem to count 3. b1, b2, and a1.

Backing up a bit, how many objects were created? I'm not really sure.
Is it seven? a1, a1.b1, a1.b2, b1, b1, a2, and a2.b2 ? Since Alpha.b1 is static, I think there is no separate a2.b1 object, the static Beta b1 belongs to the class Alpha.
or is it four? a1, b1, b2 and a2. The variables in the Alpha class are reference variables, not objects.

You created 4 objects. Objects are only created when "new" is used. You used new 4 times, so you have 4 objects created.

still, setting b1 and b2 both equal to null, seems to make them eligible for GC.

b1 was assigned to Alpha.b1 and will not be eligible for GC until the value of Alpha.b1 is changed.

Does setting a2.b2 = b2 mean the code can still reach b2, so b2 (although null) is not eligible for GC?

a2.b2 does mean that you can still reach b2. So setting b2 to null will not make it eligible for GC.

BTW, I would never assign Alpha.b1 us using the static member of a instance like a1.b1. Most IDEs will point this out as a potential source of a bug.
13 years ago
I know this is an old post, but I found it while researching this issue and I found out why I was getting it.

Another cause of this problem....

If your Engine in your server.xml is not "Catalina", you will need to reproduce the directory structure at <CATALINA_HOME>/conf/Catalina as:

<CATALINA_HOME>/conf/<engine name>

The localhost and the xml files have to follow the same directory structure.
15 years ago

Originally posted by Ron Yorrick:
When I test the program with the file already open in notepad, the program is still able to get a lock on the file even though I expect it not to be able to.

Note Pad does not lock the file. The same is true with Wordpad.

MS Word does however lock the file.

16 years ago
Can you post the code where you created the serialized Secret Key?

Keys are based on the implementation. Perhaps you don't have the right cipher suite in your classpath? Or maybe there is something in the way you are writing the serialized object.

16 years ago
After re-reading your post, you have another issue.

Your opening the file each time. I suggest that you open your outputstream once and keep it open. You can do this in your Servlet.init() method and close the outputstream in your Servlet.destroy() method.

But your first statement is correct, you should be using a logging framework that does all of this heavy lifting for you.


Originally posted by Joseph Kampf:
You are using FileOutputStream directly?

I suggest that you try passing your FileOutputStream into the constructor of a BufferedOutputStream, then write to the BufferedOutputStream.


16 years ago
You are using FileOutputStream directly?

I suggest that you try passing your FileOutputStream into the constructor of a BufferedOutputStream, then write to the BufferedOutputStream.


Originally posted by Jay Damon:
I know I should probably be using a logging mechanism but bear with me (baby steps please).

I am working on a web application that logs page accesses to a mapped Windows drive. This has become somewhat of a bottleneck in the application. My first approach was to spin the logging process off as a thread. However, I have discovered that doing so is still somewhat expensive.

However, I have discovered that by hanging onto the reference to the OutputStream/Writer object and invoking flush() after the write, I can increase performance by a factor of 10 or more. This concerns me though because the object will never be explicitly closed.

The PageLogger class I have written for testing purposes invokes close() in its overridden finalize() method but I'm concerned that is not sufficient.
Is this a reason for concern or is there perhaps some other option I am overlooking?

16 years ago
Well first thing you need to do is convert the Binary Data into a String. Do you have the code that put the XML into the BLOB? Is it on the same platform?

When you call the getBytes() method of a string, you use the default character encoding for the platform the JVM is running on. You do have the option of passing a Character encoding to the getByte() method to specify how the String is converted into Bytes. Check out the JavaDoc for getBytes() method on java.lang.String for how to do this.

Once you figure out what encoding, you then need to gather your bytes and create a String. You can do this in a loop that reads the ByteInputStream into an array. Then you can construct a string that contains your XML with the String(byte[] bytes, String charsetName) constructor.

After you have your XML in a string it is easy to open a FileWriter and write the String to the Writer.

Originally posted by Reddy Anoop:

I need help/suggestion on how to resolve the following issue.
I need to read an xml file stored in as BLOB in an oracle table. I am able to read the file. I am stuck after this because, I am calling another java program to parse by passing in an XML file. Since I am not sure how to convert the BLOB to an xml file, I am getting no where. Any suggestions/help is greatly appreciated.
Here is what I need to do.
1. Read BLOB data type from xml
2. Convert the BLOB into an xml file and call the parser program with this
xml file as the parameter.


16 years ago
[FBR - let's try to be a little nicer]

Originally posted by xiao sean:
hi guys,

i need a help on this assignment. the question is to require me to print a letter X onto screen using *.

but no matter how i try, the o/p is


any advice please?
* Write a description of class ForEg3 here.
* @author (your name)
* @version (a version number or a date)
class ForEg3
public static void main (String[]args)
for (int row=1; row <=5; row++)
for (int col=1; col <=5; col++)

if (row==col || (col <= (5-col)) )
else System.out.print("^");


[ August 22, 2007: Message edited by: Fred Rosenberger ]
16 years ago
What you are doing is essentially creating a duplicate of your large map in memory. And it is even worse than that, because serialized version of this map is a lot larger than how the map is represented on the heap.

What are you doing with the ByteOutputStream after you are done? Writing it to a blob? A file? Sending it over the network? If so, I would skip the middleman of the ByteOutputStream and send it directly to the destination OutputStream.

Originally posted by Tom Griffith:
Hello. If somebody has a minute, I seem to be going in crocles on this one. I have a hashmap (referenced as data_map) that i am serializing, however, when I load test it, i run out of java heap space...

ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);

i've been trying to go about maybe chunking the hashmap into the ObjectOutputStream but it all comes back to the inability to read/write the object as is to any stream (to convert it to bytes). I appreciate any help and input. Thank you.

[ August 22, 2007: Message edited by: Tom Griffith ]

16 years ago
It will NOT be replicated.

Each WLS Server has it's own copy of the JNDI tree. Only Cluster Aware Stubs (Such as Queues and EJBs that are marked as such) are replicated. And when this happens, each server still has their own copy of these objects. Just that the implementation of these objects knows how to get a hold of the other instances of these objects in the other servers.

Originally posted by Senthil Kumar SS:
In our application we bind an HashMap to the InitialContext. My doubt is will this be replicated to the available managed servers when the current managed server goes down.

16 years ago
You are ignoring exceptions. Print out the exception in your catch block. That will probably give you more information as to what is happening.


Originally posted by yathamshetti ramchander:
this is program is compiling and running but nothing is displayed

i created separate Domain as ramchander
and usename is : ramchander
pwd : rampassword

i configured weblogic

import javax.naming.*;
import java.rmi.*;
import java.util.*;

public class UseJndi{
public static void main(String args[]){
Hashtable h = new Hashtable();
h.put(Context.PROVIDER_URL, "t3://localhost:7001");
h.put(Context.SECURITY_PRINCIPAL, "ramchander");//userName
h.put(Context.SECURITY_CREDENTIALS, "rampassword");//password
Context ic = new InitialContext(h);
System.out.println(" initial context = "+ ic);
NamingEnumeration ne = ic.listBindings("");
while (ne.hasMore()) {
Binding b = (Binding);
System.out.println( b.getName());
}catch (Exception e){}
i compiled
java UseJndi
no answer...

> tell me where to keep above file
> give me steps to execute the above program.....

16 years ago

Originally posted by thomas jacob:
Can a production application run on the administration server?. Please confirm whether production application can only run on managed servers and not admin server of weblogic.

You can do it. Before you do that however, you want to make sure that someone out side of your file wall can't call your application with /console. You can accomplish this by a reverse proxy like Apache so that only your application URLs get exposed.

However, I don't recommend running a production application in an admin server.
16 years ago
I'm not sure what your test code is trying to do.

However, B's parent is not java.lang.Object. B's parent class is A. Yes you can do something like:

Object b = new B();

And even:
A a = (A) b;

But you can do the same with interfaces, which don't have constructors. How you reference an instance has no bearing on it's constructor hierarchy.


public class B extends A implement I{

You can do:

I i = new B();



Originally posted by Tony Smith:
I think B is also an object, by definition all object has default constructor. Check out my following test code, it run just fine...


16 years ago
If your requests take 1 second then yes you will need 3000 threads to stay on top of things. But you design your application to be fairly stateless you should be able to take advantage of horizontal scaling.

Now if your response time is say, 1/2 second, you can do it with 1500 threads. That is a little bit of a smaller pill to swallow. If you can get your process time down to 1/4 second then you should easily be able to handle this. This is processing time, not round trip time.

Originally posted by Ransika deSilva:
Hi all,
I want to develop an application which gets 3000 Asynchronous requests per second and I would be very glad to hear your expert ideas on this? This application is intended for the Wireless market. So far I have done some research on Mobicent application and sounds promising. But I am not very clear on this particular point; if a thread is created to handle an incoming request, we need to create 3000 threads per a second, which I am sure not very good. So what are the frameworks which I can do the research on. Thanks and regards.

16 years ago