Robert Kennedy

Ranch Hand
+ Follow
since Jun 27, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Robert Kennedy

Thank you. I made these changes based on your observations.
14 years ago
Thank you for the response. I am trying to get a pointer on how to restructure this code so it does not use paint component.
14 years ago
Here is an example of a swing applet which uses paintComponent. The paintComponent method is called almost non stop. I can prevent its executing by setting a flag which prevents the thread from continuing once it enters the paintComponent method - unless there is actually a change in the data.

However I believe there must be a design solution to this issue or perhaps just a better design which does not use paintComponet but instead calls repaint?? All the objects in paintComponet are native - no custom graphics.

Any advice please.

Thanks!

link to code snippet:
http://pastebin.com/f9BEPBc4
14 years ago
Hello,

Is it possible t o add an onclick handler (via a mask or directly to the text) to text rendered via drawChars.

if not how would i render a JLabel component at the precise coordinates as the drawChars woudl have rendered.

Thanks!
14 years ago
Hello

I am tryng to write a cookie to the request. How do I indicate the root path or the equivalent of setPath=("/")

req = "GET "+uri+" HTTP/1.0\r\nCookie: JSESSIONID="+session+"\r\n\r\n";

Thanks
15 years ago
Thank you for your responses.

I am not using swing, however I have seen some of the examples. The gui is in HTML but it is fed by the applet via javascript.

The progressbar thread wakes up every second and checks a number of queues
to determine if it should update to the gui. The progress bar is one of these.

The writer thread writes all its data (0-100% in the while loop) in less than a second and then waits for a response for 3 seconds.

It may be prudent to have a wait\notify relationship between these two threads. However in this problematic scenario the gui would attempt to write 50 times a second. The write thread did not really write the file in one second. i believe this is confirmed by the 3 second wait for a response. Something appears to be amiss in the write algorithm.

But i am using a very standard implementation OutputStream and OReilly. No buffer, or so it appears.
16 years ago
Hello,
Thanks for your response.

The writer thread puts bytes sent in a queue and the progress bar thread wakes up on it own, every second, to update the progress bar. There is no direct notification between the writer thread and the progress bar thread.

The issue appears to be that, at times (often),the writer threads writes very quickly in its while loop and then wait a long time for a response (perhaps indicating the data was not really written but somehow buffered). when the progressbar thread wakes up it updates 100% to the progress bar and the interface remains like this until a response is received by the writer thread and the next item is started.

I wonder about my implementation. Is it correct?

note: If I place a 150ms delay between each write in the while loop all behaves as expected (desired), but this is not the solution. i would prefer to resolve this issue.

Thanks!
16 years ago
There are five active threads in this applet.
ThreadOne is writing data to the os stream.
ThreadTwo lives in a wait/notify loop and wakes up (timeout on wait/notify)
every second to update a progress bar and statistics, using values stored in
a object (to which this thread has exclusive access).
The other threads are living in there own wait/notify loops and are not active unless noified.


problem scenerio:
On occasion - most of the time - ThreadOne rushes through the while loop writing data for a 2mb image in less
than a second and then waits for a longer time for a response.

ThreadTwo never has a chance to update the progress bar when ThreadOne rushes through the while loop, either because the
time span is too short or ThreadOne aggressively holds the cpu?

Between the while loop and waiting for a response code ThreadTwo gets a chance to upload the progress bar
which it updates to 100% as ThreadOne appears to have written all data to the stream in the while loop.

Then there is a long wait (for a response) while, i suspect, the data is actually being written to the stream or to disk.

Eventually the upload is completed and the same behavior may repeat for the next file.

The corresponding console output is (for each image where the 1657 and 1907 times indicates problematic behavior):
bufferSize: 8192, whileloopWriteTime: 40125, waitForResponseTime: 500
bufferSize: 8192, whileloopWriteTime: 31937, waitForResponseTime: 625
bufferSize: 8192, whileloopWriteTime: 1657, waitForResponseTime: 27843
bufferSize: 8192, whileloopWriteTime: 1907, waitForResponseTime: 33734
bufferSize: 8192, whileloopWriteTime: 48719, waitForResponseTime: 641
bufferSize: 8192, whileloopWriteTime: 34578, waitForResponseTime: 688


Could there be a problem with my implementation (OutStream or the backend use of O'Reilly's MultipartRequest)?




more console output normal behavior:
starting from whileloop:

ThreadOne: write file: 8192 : 8192
... etc
ThreadOne: write file: 8192 : 2351104
ThreadOne: write file: 8192 : 2359296
ThreadOne: write file: 8192 : 2367488
ThreadOne: write file: 8192 : 2375680
ThreadOne: write file: 8192 : 2383872
ThreadOne: write file: 8192 : 2392064
ThreadOne: write file: 8192 : 2400256
ThreadOne: write file: 8192 : 2408448
ThreadOne: write file: 8192 : 2416640
ThreadOne: write file: 8192 : 2424832

ThreadTwo: updating progress barandstatistics: 03A.jpg : bytes sent: 2424832

ThreadOne: write file: 8192 : 2433024
ThreadOne: write file: 8192 : 2441216
ThreadOne: write file: 8192 : 2449408
ThreadOne: write file: 8192 : 2457600
ThreadOne: write file: 8192 : 2465792
ThreadOne: write file: 8192 : 2473984
ThreadOne: write file: 8192 : 2482176
ThreadOne: write file: 8192 : 2490368
ThreadOne: write file: 8192 : 2498560
ThreadOne: write file: 8192 : 2506752
ThreadOne: write file: 8192 : 2514944
ThreadTwo: updating progress bar and statistics: 03A.jpg : bytes sent: 2514944

... etc

ThreadOne: write file: 8192 : 2621440
ThreadOne: write file: 8192 : 2629632
ThreadOne: write file: 8192 : 2637824
ThreadOne: write file: 8192 : 2646016
ThreadOne: write file: 8192 : 2654208
ThreadOne: write file: 8192 : 2662400
ThreadOne: write file: 8192 : 2670592
ThreadOne: write file: 3826 : 2674418

ThreadTwo: updating progress bar and statistics: 03A.jpg : bytes sent: 2674418


ThreadOne: write final boundry
ThreadOne: read response: (03A.jpg)
bufferSize: 8192, writeTime: 29265, responseTime: 110
ThreadOne: cleanup
============================================================================

more console output problematic behavior:

ThreadOne: write file: 8192 : 8192
... etc
ThreadOne: write file: 8192 : 2351104
ThreadOne: write file: 8192 : 2359296
ThreadOne: write file: 8192 : 2367488
ThreadOne: write file: 8192 : 2375680
ThreadOne: write file: 8192 : 2383872
ThreadOne: write file: 8192 : 2392064
ThreadOne: write file: 8192 : 2400256
ThreadOne: write file: 8192 : 2408448
ThreadOne: write file: 8192 : 2416640
ThreadOne: write file: 8192 : 2424832
ThreadOne: write file: 8192 : 2433024
ThreadOne: write file: 8192 : 2441216
ThreadOne: write file: 8192 : 2449408
ThreadOne: write file: 8192 : 2457600
ThreadOne: write file: 8192 : 2465792
ThreadOne: write file: 8192 : 2473984
ThreadOne: write file: 8192 : 2482176
ThreadOne: write file: 8192 : 2490368
ThreadOne: write file: 8192 : 2498560
ThreadOne: write file: 8192 : 2506752
ThreadOne: write file: 8192 : 2514944
ThreadOne: write file: 8192 : 2621440
ThreadOne: write file: 8192 : 2629632
ThreadOne: write file: 8192 : 2637824
ThreadOne: write file: 8192 : 2646016
ThreadOne: write file: 8192 : 2654208
ThreadOne: write file: 8192 : 2662400
ThreadOne: write file: 8192 : 2670592
ThreadOne: write file: 3826 : 2674418

ThreadTwo: updating progress bar and statistics: 04A.jpg : bytes sent: 2674418


ThreadOne: write final boundry
ThreadOne: read response: (03A.jpg)
bufferSize: 8192, writeTime: 1907, responseTime: 33734
ThreadOne: cleanup
============================================================================
16 years ago
I am using two threads. One writes data to an OutpputStream and the other updates a progress bar. The behavior I am observing is such that the file write loop is executed until all data has been transferred and then it waits for a response for another few seconds. All this time (4-5 seconds) the progress bar thread does not wake up. The progress bar thread is programmed to wake up every second.

From what I have read it is possible that the jvm and os are not allowing the progress bar thread cpu access, given both threads have the same priority. Is this correct?

Also I notice that the file data is written at and then there is a lag waiting for a response. Is it possible that some sort of cache is happening despite the fact that the thread is writing directly to the OutputStream class.


The example you provided illustrates the behavior I am observing and also a few possible solutions.

Thank you.
Thank yo for your response.

Is it possible that the thread which i am using to write the file to either bos or os is manipulating the cpu to the point where the thread used to update the progress bar cannot access the cpu?
i would like the progress bar to increment at the same speed as the write to disk. If the BufferedOutputStream buffers the data and writes it later then my progressbar reflects the speed with which data is transfered to a buffer and not to the disk. And because I wait for a response indicating the number of bytes which were written to disk there is a lag between the progressbar at 100% and the actual fact of the data being written to disk. Is this correct? And then should OutputStream remedy this symptom?
Hello,

I wish to increment a progress bar in real time (file upload). If i use a BufferedOutputStream it appears to move too quick. is it that the
data is being written to the stream and the thread moves on. I tried OutputStream which appears realistic. Is this the correct way to implement this?

Thanks
Thank you for your response. What I require is a mean to set the connection size (initialSize) using Java directly, not a configuration document.
Hello,

I am trying to control the number of initial connection when creating a connection pool (Apache-Postgres). I require 1-2 connections but i am initially receiving 4. I see that in BasicDataSource i can set the initialSize of the pool, however i do not understand how to set initialSize using PoolingDataSource.

Thanks,