John Ryan

Ranch Hand
+ Follow
since Mar 14, 2001
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
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by John Ryan

Hi guys,

I was wondering if there are any well known OO principles or refactorings that indicate when you should subclass when creating a Class which is primarily a data holder. The following (poor) example illustrates my question:



Typically a Person will always have a first name and last Name. However the children and driversLicenseNum fields may not always be populated. The children field will have only have values if the person is a parent. They will only have a driversLicenseNum if they have a drivers license. Does this situation where some of the attribute of Person are only populated when certain conditions are true indicate that I should subclass Person so that we have two new subclasses "Parent" and "Driver"?

Any tips you could give me on this would be much appreciated.

Thanks,
John
Hi guys,

I have a multi-threaded Java application which acts as both a CORBA client and server. As a client there are multiple threads which can invoke methods on the server and each of these threads share a single object reference to the object on the server which carries out the necessary processing.

I'm wondering if there are any issues (performance, thread safety or others) with having multiple threads sharing the same object reference?

Thanks for your help,
John
11 years ago
Hi,

We are converting a monetary value (say dollars and cents) which is stored in a Double into an integer which stores the number in cents by multiplying the value by 100. I would have expected this to work without a problem but I recently discovered that we do not always get the value we expected e.g. if a double contains the value 2.07 and is multiplied by 100 the result is not 207.000 but 206.99999999999997
But if 2.18 is multiplied by 100 the result is 218.00000000000003.

This can be seen by executing the following code




Im sure that this is some feature of the IEEE floating point standard that I dont fully understand but what now concerns me is how I can fix this problem so that the cent value is always correct. Would it be enough to round my double value up before converting it to an int as follows



All comments appreciated.
John
12 years ago
Thanks Kristin. This fully explains the difference
12 years ago

Originally posted by Steve Morrow:
Operator Precedence



Hi Steve,
This just seems to cover precedence and I fully understand this. What I dont understand is associavity and how it differs from precedence.

Cheers,
John
12 years ago

Originally posted by Kristin Stromberg:
I think you're confusing associativity with precedence. They're not the same thing.



Okay thanks Kirstin. can anyone explain to me what associatity means with respect to logical operators. also what is the difference between associativity and prededence?

Cheers,
John
12 years ago
Hi guys,
Sorry one more for today

I am reading a tutorial on logical operators and it states "The associativity of the &&, ||, &, | and ^ operators is from left to right." It also includes a diagram of these operators in the order above with an arrow moving from left to right.

This does not seem to match the precedence rules I have found on a number of web sites e.g. http://www.uni-bonn.de/~manfear/javaoperators.php

I think the order of precedence should be &, ^, |, &&, ||
Can someone verify this for me (and that the tutorial is incorrect)?

Cheers,
John
12 years ago

Originally posted by Edwin Dalorzo:


Now, if the shifted value is assigned back to a byte the upper 16 bits will be discarded.




Hope it helps.

[ June 18, 2005: Message edited by: Edwin Dalorzo ]




Do you not mean that the upper 24 bytes will be discarded - given that a byte has only 8 bits (32-8 = 24) ??
12 years ago

Originally posted by John Ryan:
Hi all,

When a left shift is performed on a byte it is first promoted to an int. When you want the result of the shifted byte value is it true that you must discard the top three bytes of the int result?. Is this because the top three bytes are used only for representing the sign of a byte or a short vaue?

This statement is confusing me because I thought the sign of a byte/short/int was only represented by the right most bit?

Cheers,
John




Thanks Stuart, I meant to say left most bit. Is the statement regarding the top three bytes true??
12 years ago
Hi all,

When a left shift is performed on a byte it is first promoted to an int. When you want the result of the shifted byte value is it true that you must discard the top three bytes of the int result?. Is this because the top three bytes are used only for representing the sign of a byte or a short vaue?

This statement is confusing me because I thought the sign of a byte/short/int was only represented by the right most bit?

Cheers,
John
12 years ago
just posting this to see my number
12 years ago
Hi all,

I was wondering if someone could tell me how to get Axis to ignore
whitespace when deserializing an XML message into Java types. I am receiving an XML string which includes whitespace as part of the contents of an element whose type is an integer. When this element is deserialized Axis throws a NumberFormatException because of the presence of the whitespace (exception is thrown by the Integer constructor). Has anyone got any ideas on ways I might get around this issue - other than searching through the string I receive for elements whose type is integer and stripping any space for element content
Cheers,
Tom
13 years ago
Hi guys,
Thanks for all your replies. They have all been very useful and extremely educating. I agree that Davids soltion is probably the best way to go given its flexability and extensibility. Priority queues are something that I had not been aware of but I have now found some articles on the Sun web site that go into some details on how to implement them. I had previously ruled out varying the actual priority of the threads purely because I dont think I understand completely the behaviour that results from having threads of different priorities.

My final question would be if you consider that our solution has suceeded in giving a higher priority to the type 2 messages??? - even though it isnt the best solution and could lead to backup of messages on the socket if the reader threads are all busy processing type 2 messages?

Cheers,
John
Hi all,

Java packages usually follow format of usuing reverse domain names e.g. developers working for a company www.google.com would put their classes in a package com.google.www.engine etc.... I am wondering if anybody has some code or knows of a library (I took a look at Apache commons but didnt find anything there) in where I might get some code that reverses the the host value of a URI so that it could be used as the name of a package.

Im sure its very simple to write but if its exists already that would be preferable.

Cheers,
John
13 years ago

Originally posted by David Harkness:

My first instinct would be to have designed it such that only one thread was reading from the socket and placing the messages into two separate queues (to be able to tune them separately). Then I would have two thread pools processing the queues.

Note that this is very similar to your design. The difference is that if all three reader threads are busy handling type 2 messages at once, the socket starts backing up. But I see a few advantages to this method:

  • Both types of messages are treated exactly the same up to the point where the actual handling of the message differs: they both get read and put into a queue.
  • Each queue and its respective thread pool can be tuned more easily.
  • Adding new types of messages just means a new queue.
  • You could have a single thread pool to handle message queues by applying an algorithm to choose which queue to poll based on queue priority and backlog.

  • I think at this point you really need to know what each reader thread is doing by adding logging if you haven't already. Figure out how long it takes each thread to complete its task (put a type 1 message on the queue, handle a type 2 message, handle a type 1 message). With that you should be able to tune your thread pools without making another architecture change.


    Hi David,
    The reason we did not do somthing like this is because we want the type 2 messages to be handled with higher priority(to prevent the timeout that was occurring on the application which they are forwared to). If both type 1 and type 2 messages were placed into internal queues they would effectively have an equal priority and this is not what we want.....