Mike Broadbear

Ranch Hand
+ Follow
since Jan 14, 2002
Merit badge: grant badges
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Mike Broadbear

I was wondering if anyone knows the time complexity of a HashMap.toArray() operation.

...Mike B.
14 years ago
I figured it out.

Just add a logger to the properties file:

log4j.logger.(package.prefix)=INFO
15 years ago
Hi,

I have an application that logs trace level, but a certain class outputs too much information and I do not have access to that source. Is there a way to continue to log trace level, but to ignore logging (or change the log level) for only that class?

15 years ago
Ok, let me try to regurgitate what I think I understand.

A Date object holds an absolute time; toString() simply uses the default timezone to format the date to what I probably would want to see, given my locality. So it becomes; absolute time -> printed BST

What I don't fully understand is why the initial method I posted seems to work. Let me take a stab at it:

step 1: format the current time according to a given timezone, store the result in a string.
step 2: parse this date string into a Date object, using a DateFormat with the default timezone. Since the original date string has timestamp relative to the given timezone, that time is translated into an absolute time with respect to the default timezone, which has the semi-unintended effect of shifting the time to where I want it.
step 3: (after method) when I print the date with toString(), the shifted absolute time is translated into something printable using the default timezone. (which is why I am now seeing Wed Jun 13 19:53:02 "BST" 2007 after passing "America/New_York" to the method).

Am I close?

I have been reading the Javadocs a little more closely, but they are not too in depth. Does Calendar work the same way? Some initial testing shows when I set the hour, minute, second fields and vary timezone with Calendar.setTimeZone(""), I always see the same timestamp and 'BST' when printing the date.

...Mike
17 years ago
If I am in Britain, and I do the following:



Will dateString contain the date in Praque local time, properly accounting for DST?

...Mike
17 years ago
Yes! British Summer Time. Thanks for the other thread.

So what you are saying is that a Date object is supposed to hold a representation of a given local time, and what I have done is to trick it into holding something else, and this is definitely not recommended?

We have an application that gathers information from locations around the world, and stores a timestamp in a database in whatever local time it happens to come from. What I want to do is compare these various local times to my current local time. Right now I am using the above method to get a modified timestamp (apart from the one hour off) and comparing the long return values of Date.getTime(). This is a date comparison task more than a formatting one.

Are there any cleaner methods to modify timezones and compare dates? I want to take advantage of the timzone DB with the JDK, and not have to deal with DST and such.

...Mike
17 years ago
Well, I can restate. I want whatever the Date object contains to reprepsent the current time in the timezone denoted in the single String argument.

Right now I am passing the timezone "GMT" and "GMT+2". Both come back everytime with a Date object that contains a representation of a date that is one hour off. For instance:

When I pass "GMT", my OS clock shows 21:17, the Date object returned from the method will contain a representation of 20:17.

I don't like to keep the date in a String as it passes through my program. It is much nicer to pass and perform opertations on the Date class.

...Mike
17 years ago
Hi,

After some research, I have come to understand the best way manipulate timezone with Date objects is with the DateFormat object. I have created the following method to return a Date object that contains the time local to a timezone. The problem is that it is returning a time that is exactly one hour previous to the correct local time. Do I need to do something special to account for DST? I am using Java 1.5.



...Mike
17 years ago
Stan,

I am not reading stderr, although I was at one point, and received similar behavior. If I run the stdout read in a separate thread, I understand the main thread will continue execution (all calls to this method are done with worker threads anyway), but won't the new tread eventually block all future attempts to read stdout?

Nicholas,

Yes, it would be interesting to know what is causing the deadlock, i.e. java thread requests native resource and needs to call back to a java resource that is already blocked by a subsequent java thread waiting to call the native resource... My testing worked fine when calls to the external application were sent sequentially, and there was no logging enabled, but in the context of the greater application, the readbytes deadlocks after a few tries.

...Mike
When I comment out the input stream from the method above, the method works without any failures, so I think it has something to do with the IO.

Also, when I try ping istead of my test .bat file, the IO succeeds (which is much more complext than the IO from my test .bat file).

Java 5 Javadoc for java.lang.Process object states that there are problems for various types of executions:


The methods that create processes may not work well for special processes on certain native platforms, such as native windowing processes, daemon processes, Win16/DOS processes on Microsoft Windows, or shell scripts. The created subprocess does not have its own terminal or console. All its standard io (i.e. stdin, stdout, stderr) operations will be redirected to the parent process through three streams (getOutputStream(), getInputStream(), getErrorStream()). The parent process uses these streams to feed input to and get output from the subprocess. Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.



Wish I knew why this was such an issue.

...Mike
Hi,

I am using a ThreadPoolExecutor to send messages to a native application. The method is in the code pasted below. When I run the method with a test harness, the code works fine. But, when I run with my application, which has a lot of logging and other stuff going on, the worker threads initiated by the ThreadPoolExecutor lock up after a couple of successful executions. I have also pasted stack traces for a few threads.

It looks like one of the worker threads deadlocks on the native readBytes call, and other worker threads are forced to wait forever. Could there be some conflict between the native readBytes and all of the logging that is going on (log4j/apache.commons.logger)?

The code:




The stack traces:

Only one is like this:


Several are like this:


...Mike
http://bear-webtech.blogspot.com/
Yes, I am subclassing each of the frames/panels from JFrame and JPanel. I came to it after trying a couple of other methods (wrapping, etc...), none of which fit quite right.

What do you suggest other than subclassing? Can you point to some literature/concepts describing best practices?

...Mike
17 years ago
Trying again:

17 years ago
I was looking for a way to avoid the messy references.

Maybe I am looking more for a design pattern. Here is what I am looking at (I hope the formatting works):

/- JTable
/- EditTablePanel<
EditFrame - EditPanel<
\ /- other buttons
\- EditButtonPanel<
\- AddButton -opens-> AddFrame

/- input fields
AddFrame - AddPanel<
\- SaveButton -send input values to EditTablePanel


It seems like the tree gets deep very fast. Plus, once I open AddFrame, getParent seems to be cut off from the rest of the app.

Is there a neat way to return the values from the AddPanel input fields to the JTable on the EditTablePanel?

...Mike
17 years ago
Hi,

I have a couple of questions about JPanel->JFrame communication:

1. I am opening a JFrame inside an ActionListener on a JButton inside a JPanel. Can I communicate with the JPanel from the JFrame via getParent() or some other method?

2. I am opening serveral JPanels inside a JFrame. Can I communicate with this JFrame via getParent() or other method?

3. In a situation with a JFrame with a primary JPanel (JFrame->JPanel), when I call JPanel.getParent(), I receive another JPanel, and it looks like a reference to the calling JPanel. Why don't I receive a reference to the JFrame? Is there a way to obtain this reference?

4. Is there a better way to open a new window than as described in #1? I basically have a main window (JFrame->>JPanel), that needs to allow the opening of another complex window to edit certain properties (JFrame->>JPanel). Given the way I am doing it (opening new JFrame from ActionLister) it looks like I will have to pass a reference to the original JPanel that contains the open button.

...Mike
17 years ago