Waclaw Borowiec

Greenhorn
+ Follow
since Dec 14, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
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 Waclaw Borowiec

I also had timeout related problem with EJB 3.0 application deployed on JBoss 4.2.3 that manifested with this kind of logs. DB transaction timeout can be set in datasource descriptor:



What doesn't fit here is that your transaction lasts below 1 minute where transaction timeout default is something around 10 minutes. But still you may have some weird settings. Besides, if it's only one transaction, only one JBoss thread should be involved in it (also during rollback), so your application should be responsive. Check which processes (JBoss, DB?) consume which resources (CPU, memory, IO?).
Are you asking about any specific OS? I think it may vary from system to system.

On Linux each Java thread is mapped to OS thread, it has its own PID, and can be found in /proc filesystem, under parent process directory. You can even watch load for each thread in top (press H to enabled it). When you make stacktrace dump of your VM with jstack, you'll see that each Java thread has its nid. It's in hexadecimal format and it maps to PID of the OS thread. This technique is very useful e.g. to find out which of out threads consumes lots of CPU.

On Windows it may be similar to some point.
Score: 95%, not that bad

Thanks to all the ranchers for all the interesting discussions I could read and take part in. This place is a great aid in process of preparation for the exam.
And good luck for all guys who still have the exam ahead of them.

13 years ago
Only Set, List and Map interfaces have a requirement to implement equals method in an elements-based way. In case of Collection it's not necessary and in a Queue it's even discouraged. That's what API for these types says.
Hi

Is object of class java.lang.Object a mutable one or an immutable one? What do you think?

Ankit Garg wrote:Someone did some extensive experimentation on this here. The results are interesting...



I have a doubt here. The author of the tests uses System.currentTimeMilis() function for measurement where its resolution is less than 1ms (about 10ms; currentTimeMilis). His average results are from 0.05 ms to 35 ms, so I'm afraid they may be inaccurate. The tests should run longer, or nanoseconds should be used here.

Ankit Garg wrote:When you iterate over elements sequentially, ArrayList is slower than LinkedList. ArrayList is faster in random access of elements, LinkedList is slow in that...



We can't say ArrayList is slower than LinkedList when iterating over it. ArrayList is implemented as an array, so iteration means going through subsequent cells in memory. In LinkedList cells are scattered in memory but linked together by additional pointers. In both cases iterating means jumping from one memory location to another and it's impossible to say that one structure is significantly faster than another.

Indeed ArrayList is much better than LinkedList in random access because we can get each element in constant time by its index (by adding it to the beginning of the array) whereas in LinkedList we have to always iterate over it until we find required element.

Neha Daga wrote:1 is answer becuse at runtime the object type is taken into consideration not the reference type, so at runtime jvm sees it as object D being casted to E and d implements E through its superclass so no exceptions will be there.



Answer 4 says that in line 4 the (E)a cast is required. And it is as the code doesn't compile without it (try it yourself). It shouldn't because in Java type safety is checked at compile time. Here we're trying to assign reference of type A to reference of type E. Class A doesn't implement interface E so this assignment requires explicit cast for the compiler. In runtime everything is fine - it's object of type D which is being cast to E, and D implicitly implements E, so no exception. That's why correct answers are 1 and 4.
The answer is 1 and 4.
There're 4 objects created. Line "d=c=b=a" assigns all 4 references to the first created object (initially referenced by a), making 3 other object eligible for GC. Last assignment "d = null" doesn't matter.

Neha Daga wrote:in this question there is no option saying "result is not predictable", and "good" is the only answer that may be a possible output so in this case I think 1 is correct answer.



What I meant is the question has no correct answer.
I refresh this thread as it lacks final answer. Original options are:

A)good
B)good idea
C)good idea good idea
D)good 0 good 0 1

but the correct one is "The output is unpredictable". Right?
Hi Tapio

When I saw the code I was pretty sure that 3rd line should compile, and that it matches myMethod(int...i). But apparently it doesn't ;)
I checked K&B, in a summary of overloading there are following points:

  • Primitive widening uses the "smallest" method argument possible.
  • You can combine var-args with either widening or boxing.


  • So it's tempting to apply these rules to the problem. Nevertheless what we'd have to do here is either use var-args method (int...) or widen and use var-args (long...). And it's not said anywhere that var-args is better than widen and var-args. We can't apply rule #1 to var-args. It's the only explanation that comes to my mind but I'm kind of creating theory for facts.
    Hi Santiago, your regexp would accept illegal string, e.g.:

    "+"
    "-"
    "."
    "+."

    I would answer the question with following regexp:

    [+-]?\d{1,9}(\.\d{1,2})?

    \d can be replaced with [0-9] of course.