Synchronized thread monitors!!! AHHH!!!
Hi,
In my program , I'm trying to start a thread which immediately begins waiting and when a notify is received the Thread executes a method and then right back to waiting. The program I'm having trouble writing is far too bulky and complicated to be easily made sense of here, so I've written this concise version:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
import java.util.*;
class syncTest1 {
public static void main(String[] args) {
syncTest2 thread = new syncTest2();
Monitor monitor = new Monitor();
try {
for(int i = 1; i <= 100; i++) {
synchronized(monitor) {
System.out.println("Notifying...");
monitor.notify();
Thread.sleep(500);
} catch(InterruptedException ie) {}
class syncTest2 extends Thread {
Monitor monitor;
syncTest2() {}
public void run() {
try {
while (monitor.progress() < 100) {
synchronized(monitor) {
monitor.wait();
monitor.increment(1);
System.out.println("Notified! Progress = " + monitor);
} catch(InterruptedException ie) {}
public Monitor getMonitor() { return monitor; }
// Used to store a dynamic integer value that can passed around as a synchronized monitor
class Monitor {
int Int;
Monitor() { Int = 0; }
public void increment(int howMuch) { Int += Math.abs(howMuch); }
public void decrement(int howMuch) { Int -= Math.abs(howMuch) * -1; }
public int progress() { return Int; }
}<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
When ran, this is the output:
java syncTest1
Notifying...
Notifying...
Notifying...
Notifying...
Notifying...
Notifying...
Notifying...
<and so on>
Notice how the monitor is never notified and syncTest1's monitor is still reacquired and able to be notified. I assume the problem lies somewhere in the trading of the monitor between classes, but for the life of me, I can't figure this one out...
Any help at all would be appreciated.
Thanks,
Jick
There are 2 things wrong.
1) You did not start your your thread.
2) You were not synchronizing on the same object.
I have also made some cosmetic changes but you are free to remove them.
import java.util.*;
public class Test20041229
public static void main(String[] args)
syncTest2 thread = new syncTest2();
Monitor monitor = thread.getMonitor();//new Monitor(); !!!!!!!!!!!!!!!!!!!!!!!!!!
thread.start(); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
for(int i = 1; i <= 100; i++)
synchronized(monitor)
System.out.println("Notifying..." + i);
monitor.notify();
try
monitor.wait(500);
} catch(InterruptedException ie)
class syncTest2 extends Thread
Monitor monitor = new Monitor();
syncTest2()
public void run()
while (monitor.progress() < 100)
synchronized(monitor)
try
monitor.wait();
} catch(InterruptedException ie)
monitor.increment(1);
System.out.println("Notified! Progress = " + monitor);
public Monitor getMonitor()
{ return monitor; }
// Used to store a dynamic integer value that can passed around as a synchronized monitor
class Monitor
int Int;
Monitor()
{ Int = 0; }
public void increment(int howMuch)
{ Int += Math.abs(howMuch); }
public void decrement(int howMuch)
{ Int -= Math.abs(howMuch) * -1; }
public int progress()
{ return Int; }
public String toString()
return "Monitor(" + Int + ")";
}
Similar Messages
-
How to VIEW two tracks's materials SIMULTANEOUSLY and SYNCHRONIZED in MONITORS?
How to VIEW two tracks's materials SIMULTANEOUSLY and SYNCHRONIZED in MONITORS?
"Program-monitor" shows the final edited material, and "Source-monitor" shows only one track at a time, and NOT SYNCHRONIZED with the sequence. "MultiCam-monitor" shows the tracks as I need, BUT editing is very stiff: I want to do edits+cross-fades by hand IN THE TIMELEINE rather than by clicking the monitors. (Some of the "MultiCam-monitor's" other problems: 1) the timeline's time-inspector doesn't move while clicking the monitors, 2) vice-versa: monitor-image doesn't roll when the space-key is pressed for playback the timeline, 3) monitor doesn't show the cross-fades.....) I understand the "Reference-monitor" doesn't help either at this.
I would SO much like to SEE all tracks' materials simultaneously in whatever monitor, to edit efficently in the timeline.
Software: Premiere CS3 version 3.2.0
Operating System: Mac OS X (v10.4)You can only do this in the multicamera monitor. That's what it's there for. Proper procedure is to cut there, then go to the timeline and add transitions.
If you're multicamera monitor playback isn't working correctly (I admit having a hard time understanding your points here), then try solving those. -
Servlet Exec Thread Monitor - MII 11.5
We have some reports that get "stuck", and they consume CPU usage, so we have to go into Servlet Exec's Thread Monitor to kill these reports.
Currently, we go into MII to manually check to see if there are any stuck reports. It would be nice if we could have MII load these log files automatically and send us an eMail when a report is stuck, so I thought we could use the HTML loader to do this. The problem is Servlet Exec has security, and it requires an ID and Password. I thought I could use the HTTP Post action block to get around this, but for the life of me, I can't get it to work.
Is it possible to use Logic Editor to open Servlet Exec's Thread Monitor screen, and if so, how?Hi Lino,
Keep the original code of the applet.
<APPLET NAME="myChart" CODEBASE="/Illuminator/Classes" CODE="iChart" ARCHIVE="illum8.zip" WIDTH="840" HEIGHT="400">
<PARAM NAME="DisplayTemplate" VALUE="Demo_Project/Vale_POC/SampleChart.xml">
<PARAM NAME="QueryTemplate" VALUE="Demo_Project/Vale_POC/QryValePOC.xml">
<PARAM Name="TagName.1" VALUE="CylTemp1">
</APPLET>
In 11.5 existis guest user. add two parameters in you applet.
<PARAM NAME="IllumLoginName" VALUE="Guest">
<PARAM NAME="IllumLoginPassword" VALUE="Guest">
I believe the best solution would be to use the SAP MII portal for developing your application and not the. NET. In SAP MII already have a lot tools ready for development of application.
If you use frame follow the link.
http://help.sap.com/saphelp_xmii115/helpdata/en/Security/Programmatic_Logins.htm
Hope this help.
Danilo Santos -
Thread monitoring for database query
Hi,
I need to be able to store a database query in a thread. This means that the entire query from executing to return should take place in this thread (as well as connection etc). I would then like to know when it have finished its work so i can carry on some more porcessing.
I tried doing this with two threads, one to do the work and the other to 'watch' and then tell me when is is done. However, i errors 'every now and again' to which i can attribute to my thread structure not working properly. I am using a synchronised class and code post the code if anyone wishes to see it, however, i would appreciate it if someone could give me a basic structure to how i can go about this so that i do not get these 'random' errors.
Thanks RudyOkay -
I have an idea. Withut fully implementing your code, mind you.
If looks like you're having problems with concurrent access to your Vector.
A Vector is, of course, a Collection and a List (interfaces) - these are not thread safe. To make them thread safe, you need to "wrap" them.
<lifted from JavaDocs>
public static Collection synchronizedCollection(Collection c)
Returns a synchronized (thread-safe) collection backed by the specified collection. In order to guarantee
serial access, it is critical that all access to the backing collection is accomplished through the returned
collection.
It is imperative that the user manually synchronize on the returned collection when iterating over it:
Collection c = Collections.synchronizedCollection(myCollection);
synchronized(c) {
Iterator i = c.iterator(); // Must be in the synchronized block
while (i.hasNext())
foo(i.next());
Failure to follow this advice may result in non-deterministic behavior.
The returned collection does not pass the hashCode and equals operations through to the backing
collection, but relies on Object's equals and hashCode methods. This is necessary to preserve the
contracts of these operations in the case that the backing collection is a set or a list.
The returned collection will be serializable if the specified collection is serializable.
Parameters:
c - the collection to be "wrapped" in a synchronized collection.
Returns:
a synchronized view of the specified collection.</lifted from JavaDocs>
Give your Vector a wrapper and see if that solves your problem.
+M -
Can't stop synchronized threads with I/O read and write
I have two synchronized threads which doing read and write from and into a file.
One thread called "reader" which does reading, encoding, etc from a source file and puts its output in a pre-defined variable. Another called "writer" which puts the reader's output into a file ( not the source file ). Both thread will notify each other when they've finished each of their part. It's similiar to CubyHole example of Java Tutorial example from Sun.
But somehow it seems like the threads keep spawning and won't die. Even if the source file has been all read and the data has been fully written, calling interrupt(), return, etc has no effect. The threads will keep running untill System.exit() called.
Is it because the threads were blocked for I/O operation and the only way to kill them is to close the I/O ?
To be honest, it's not only stop the threads that I want to, I also want to somehow pause the threads manually in the middle of the process.
Is it possible ?
Cheers.!!!The example code for the problem using 4 classes called :
- libReadWrite ( class holding methods for aplication operations )
- reader ( thread class responsible for reading data )
- writer ( thread class responsible for writing data )
- myGUI ( user interface class )
All of them written in different file.
// libReadWrite
pubic class libReadWrite {
private boolean dataReady;
private String theData;
//read data
public synchronized void read(String inputFile) {
while (dataReady == true) {
try {
wait();
} catch (InterruptedException ex) {}
RandomAccessFile raf = new RandomAccessFile(inputFile, "r"); // I'm using raf here because there are a lot of seek operations
theData = "whatever"; // final data after several unlist processes
dataReady = true;
notifyAll();
public synchronized void write(String outputFile) {
while (dataReady == false) {
try {
wait();
} catch (InterruptedException ex) {}
DataOutputStream output = new DataOutputStream(new FileOutputStream(outputFile, true));
output.writeBytes(theData);
dataReady = false;
notifyAll();
//Reader
public class reader extends Thread {
private libReadWrite myLib;
private String inputFile;
public reader (libReadWrite myLib, String inputFile) {
this.myLib = myLib;
this.inputFile = inputFile;
public void run() {
while (!isInterrupted()) {
myLib.read(inputFile); <-- this code running within a loop
return;
public class writer extends Thread {
private libReadWrite myLib;
private String outputFile;
public writer (libReadWrite myLib, String outputFile) {
this.myLib = myLib;
this.outputFile = outputFile;
public void run() {
while (!isInterrupted()) {
myLib.write(outputFile); <-- this code running within a loop
try {
sleep(int)(Math.random() + 100);
} catch (InterruptedException ex) {}
return;
//myGUI
public class myGUI extends JFrame {
private libReadWrite lib;
private reader readerRunner;
private writer writerRunner;
//Those private variables initialized when the JFrame open (windowOpened)
libReadWrite lib = new libReadWrite();
reader readerRunner = new reader("inputfile.txt");
writer writerRunner = new writer("outputfile.txt");
//A lot of gui stuffs here but the thing is below. The code is executed from a button actionPerformed
if (button.getText().equals("Run me")) {
readerRunner.start();
writerRunner.start();
button.setText("Stop me");
} else {
readerRunner.interrupt();
writerRunner.interrupt();
} -
HTTP Acceptor Thread Monitoring
I'm attempting to monitor the HTTP Acceptor Thread pool in a Production environment. JMX Monitoring threshold has been set to HIGH but I still can't seem to find the pool monitor. I see HTTP Listener Threads, but not acceptor thread monitoring.
Is there any way to achieve this?Hi,
Do you really need a HTTP Sender communication channel. Generally there is no need for a Sender communication channel for HTTP and IDOC adapter. They directly come into Integration engine.
This would be the URL for communicating
http://<hostname:port>/<path>?<query-string>
The <query string> contains the following data:
Sender namespace ?namespace=<namespace>
Sender interface &interface=<interface>
These details define the sender interface.
Sender service &service=<service>
Sender party (optional) &party=<party>
Sender agency (optional) &agency=<agency>
Sender scheme (optional) &scheme=<scheme>
Thanks,
Prakash -
I am using Java threads in my Java program, running on Windows Professional 2000. I am monitoring the threads using Windows Performance Monitor (WPM). However, even running a small Java program which creates only 2 threads, results in many (at least 10) instances of Java threads being reported by the WPM. Problem is, in WPM, there is no way to determine which threads in the WPM are the threads that I programmatically created. Any ideas on how to determine this?
Thanks.
RhodieHi Dmirty ,
To handle large asynchronous message in queues you can use message packaging where multiple message are processed in one package . to make it applicable you have to perform these simple steps
1. go to SXMB_ADM add one RUNTIME parameter PACKAGING and value 1
2 GO TO transaction SXMS_BCONF set delay time 0 message count 100 messages and package size 1000 KB
with these setting your improvement will increase .secondly also put IN SXMB_ADM monitor category parameter QRFC_RESTART_ALLOWED TO 1
this will automatically start your queue . Only thing you have to take care if you enable packaging them don't keep too many parallel queue i.e EO_INBOUND_PARALLEL and EO_OUTBOUND_PARALLEL should be less than 20
Regards,
Saurabh -
Hi.
I want to monitor thread usage in portal.
Where can I do this ?
I already try "System management -> Monitor -> Thread overview" but I don't know this is correct information.
Welcome any comments.
Regards, Arnold.Hi Arnold,
Yes that is the correct place
Regards
Arun -
Thread Monitoring in a clustered BPEL environment
Hi BPEL community,
does anybody know how I can monitor the "Pending Requests" and "Thread Allocation Activity" (BPEL Console - Threads) over all cluster-nodes? Inside the BPEL Console I only see the data of the cluster-node I'm logged in.
I was not able to see an over-all cluster-nodes view of the load on the bpel-engine.
Regards, HaraldI am not familior with anything called Quartz but I think this issue should be handled task scheduler itself.
In the place I work the task scheduler we use (I house developed one) has following approach
Once the task is posted it is in "posted" state and once a batch server (Thats what we call the service that executes it) picks a task up it changes the state to "executing". Once the execution is complete it change the state to "ready". If an exception occures it will abort the operation and set the state to "error".
Batch Server can pick up only the tasks with state "Posted" so two services will not pick up same task.
By the way the tasks with error state can be reset to posted state by the user.
probably you need a solution like this. Either you have to develop one or find one which considers the existance of multiple execution services -
Synchronous message monitoring
Hi guys,
I want to know how to monitor successfuly processed synchronous messages as they are not shown in sxmb_moni.
regards,
keith.Hi Venkat
goto SXMB_ADM
Integration engine configuration
and add the entries
RUNTIME LOGGING 1
RUNTIME LOGGING_SYNC 1
it should help...
Regards
Dheeraj -
Hi,
I am trying to solve something like a producer-consumer problem in Labview
(thinking about Mesa-style monitors) but having a problem. It does not seem
like the Notify VIs can atomically release a lock and go to sleep.
Am I missing something?
-joey"valiot" wrote in message
news:[email protected]..
> Why is the Notifier not working for you?
> If you want the "wait on notification" vi to sleep then do not wire
> the timeout value. Otherwise the wait function will timeout and
> wake-up at the specified timeout value.
Indeed, that works fine. I guess I should have been more specific. My
understanding of Mesa-Monitors (just school, I am no expert) is that you
must hold a lock before you wait() for a condition variable, and then wait()
should atomically release then wait for the condition variable. That way
whatever you signaled is blocked until after the wait() is complete.
The problem becomes that I can implement locks with semaphores, and I can
implement wait/signal with notify VIs, but I don't see how I can atomically
release a lock and wait().
It is of course possible to signal, unlock, wait. However "worst case" is
that the signalled thread executes, signals, and the first thread was not
waiting at the time so it misses the signal; unlikely but possible. In some
cases it is possible to check the history for missed signals but it seems
programmatically clumsy and does not always fix the problem.
In short... Are monitors actually possible given the resources available? I
was somewhat confused by the lack of atomic unlock/sleep.
-joey -
How are Apple Support Communities threads monitored?
While most threads seem to be about solving problems, or discussions on using products etc, I recently say two threads disappear, probably because the original posters were ranting, being overtly critical of Apple, and insulting other community members without reason. The threads really had no value at all.
Do Apple employees actively monitor these threads? Or is it only after someone reports an abuse, or as you level up do you get special priveledges to boot people. XD"Do Apple employees actively monitor these threads? Or is it only after someone reports an abuse, or as you level up do you get special priveledges to boot people."
It's a combination of both. Upper level users can report abuse on any observed topic or poster in a topic. There are also moderators who monitor the forums. They are Apple employees. -
DPS 6 worker threads monitor command?
In the deployment guide it states:
Directory Proxy Server allows you to configure how many threads the server maintains to
process requests. You configure this using the server property number-of-worker-threads,
described in number-of-worker-threads(5dpconf). As a rule of thumb, try setting this number
to 50 threads plus 20 threads for each data source used. To gauge whether the number is
sufficient, monitor the status of the Directory Proxy Server work queue on cn=Work
Queue,cn=System Resource,cn=instance-path,cn=Application
System,cn=DPS6.0,cn=Installed Product,cn=monitor.
How do you do an ldapsearch on monitor in a dps? I dont know how to do the command suggested in the manual.ldapsearch -p port -h host -b cn=monitor -D 'cn=proxy manager' -w password cn=*
-
I m writting an application which runs several tests to test network connections.The interval at which the tests run and other configuration values are downloaded from a web-site.After performing the tests it posts the data back the web-site.My problem is when the program downloads settings after every xmins it deletes the existing file(XML) and so if the other if the threads are trying to access the same fiel to retrive values it gives an error.I want to know how can i let other threads not access the file at the same time as it is beeing deleted.
I tried the file.exists to check if it does exist before the threads access to get values but it doesn seem to work.Also my file.delete method doesnt delete the file and appending the new file to the existing one.
Thnx for any input in advance.Sorry I didnt explain my problem clearly. Like I
mentioned before..I have Settings class which
downloads a settingsconfig file. The values from
this file are then used by 4 classes using Timer
Tasks to execute their operations.The settings file
is downloaded after every x mins and the existing
file gets deleted.Ideally all the timer Tasks should
get their values from the settings file everytime
execution is perfromed,but for some reason once the
values are taken from the settings file the new
values from the Settings file are not used. I hope
this makes my problem clearer.And do you test the return value of the delete?
Are you testing that you actually opened the file successfully? Are you testing that you actually wrote the new file?
And why does each task read the file? Why is the file just not read once? Why do the tasks read the file at all? One thing should read the file, and CLOSE it, then it keeps a copy in memory. And the tasks ask that for the file. -
Synchronizing threads of different JVM
I have two threads running in two different JVMs. Now I want to synchronize these two threads calling a method.
Can any one give me a solution for the same.I have two threads running in two different JVMs. Now
I want to synchronize these two threads calling a
method.
Can any one give me a solution for the same.Presumably you think that the Java API has such a method. If so then the answer is no.
You could write a bunch of code that uses sockets to send messages back and forth and then have one thread wait for a response. That isn't sychronization however. And conceptually it isn't a good idea to think of it that way either. Threads exist solely within a single process.
Maybe you are looking for
-
I recently upgraded to an HP PC with i7 chip, 8 GB RAM, 1TB data drive and 640 System drive. In PE 9, I find that if I trim 6 to 8 clips or do some other number of operations, I often get a freeze. Similar thing happens in Photoshop if I edit pict
-
Installation option...?
I'm trying to install 10.2 on iMac G3 (333 MHz), that is running on 9.2. The options I'm offered are Install (for the first time OS X install), and Erase and Install (erases entire disc before installation. I will also have format the disc for this o
-
Hide button save on page bsp hap_document.html
Hello, Do you know if there is a way to hide the button 'save' in the appraisal document page ? There is a BADI ? Regards, Aurélien
-
Always getting 'import cannot be resolved' for IPrivate* imports
Hi, Everytime I import a Web Dynpro DC from our NWDI I see 'import cannot be resolved' errors when I open for example the Component Controller implementation. An Organize Imports does not fix this. If I rightclick inside the code and select 'Show in
-
Accessing WebDAV volume from 10.4 hangs finder
I am trying to access a WebDAV volume on a 2003 server on my 10.4.4 iMac G5. If I connect to the server, I am asked to authenticate, at which point the volume mounts on the desktop, but the Finder hangs. If I look at the running processes using "top"