Joseph Kampf

Greenhorn
+ Follow
since Mar 04, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by 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.

6 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.


Given

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.
6 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.
9 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.

Joe
10 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.

Joe
10 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.

Joe


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.

Joe



10 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.

Joe



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?

10 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:
Hello,

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.

Regards
Anoop

10 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)) )
System.out.print("*");
else System.out.print("^");
System.out.println();
}
}
}

---------


[ August 22, 2007: Message edited by: Fred Rosenberger ]
10 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);
out.writeObject(data_map);

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 ]

10 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.

10 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.

Joe


Originally posted by yathamshetti ramchander:
hai
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
http://localhost:7001/console/login/LoginForm.jsp


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

public class UseJndi{
public static void main(String args[]){
try{
Hashtable h = new Hashtable();
h.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
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)ne.next();
System.out.println( b.getName());
System.out.println(b.getObject());
}
}catch (Exception e){}
}
}
i compiled
javac UseJndi.java
java UseJndi
no answer...

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

10 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.
10 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.

Assume:

public class B extends A implement I{
}

You can do:

I i = new B();

Thanks,

Joe


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...

}

10 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.

10 years ago