Cfajaxproxy problem
Hi everyone,
i have a little problem using the cfajaxproxy tag or any other tag using ajax.
here is a the code
<cfajaxproxy cfc="mdh.dev.test.proxy" jsclassname="proxy" />
function testFunction() {
var instance = new proxy();
instance.setCallbackHandler(functionSuccess);
instance.testing();
the result in the source will be:
<script type="text/javascript">
var _cf_proxy=ColdFusion.AjaxProxy.init('/dev/test/test/proxy.cfc','mdh.dev.test.proxy');
_cf_proxy.prototype.testing=function() { return ColdFusion.AjaxProxy.invoke(this, "testing", {});};
</script>
the " mdh " is a logical mapping in coldfusion admin and in IIS
i can't find why the url is trunked in the source result.
instead of being
var _cf_proxy=ColdFusion.AjaxProxy.init('/mdh/dev/test/test/proxy.cfc','mdh.dev.test.proxy');
it create
var _cf_proxy=ColdFusion.AjaxProxy.init('/dev/test/test/proxy.cfc','mdh.dev.test.proxy');
anyone else having this problem ?
tyvm
I have a related question:
<cfset testObject=createobject("component","mdh.dev.test.proxy")>
what values for createobject() would I use if my testing server is
http://192.168.1.128:8500/mdh/dev/proxy.cfc
and my file, under windows, is located at: C:\ColdFusion8\wwwroot\mdh\dev\test\proxy.cfc ?
what values for createobject() would I use if my testing server is
http://192.168.1.128:8500/mdh/dev/proxy.cfc
and my file, under windows, is located in a different folder: C:\ColdFusion8\wwwroot\mdh\CFCs\proxy.cfc ?
Thanks
Similar Messages
-
CFAJAXPROXY problem, need help !
I created subdomains on my server for development part of my website and the cfajaxproxy is working great on the live version and on my subdomain dev.mydomain.com. I created a new subdomain name dev2.mydomain.com and now the cfajaxproxy isn't working on that one. I've check my admin panel and all but I'm enable to find anything that can change the configuration specificaly for cfajaxproxy.
Anyone have a clue about that ?
Thanks all lot !I suspect that CF is generating HTML script tags with src values that point to a directory that is not on your dev2 site. CF generally expects to find its JavaScript files and other resources in the /CFIDE directory subtree. I suspect you will need to map the physical directory where the CFAJAX component are, probably in /CFIDE on your root web site, to a virtual directory on your dev2 domain site.
-
We just upgraded to ColdFusion 9 on a Windows Server 2003 box that uses IIS 6 to serve the sites.
Now that we've upgraded all of our <cfajaxproxy> tags are broken. Here is a sample: <cfajaxproxy cfc="getReports" jsclassname="GetReportsInfo">. The cfcs reside in the same directory as the cfm pages but we are getting an error that says "The specified CFC getReports could not be found.
The path to the CFC must be specified as a full path, or as a relative path from the current template, without the use of mappings."
It doesn't make sense that if they are in the same directory as the calling program then why can't it find them.Yes we're running the site from an IIS virtual directory. I tried the
real directory path with both \ and . notation but I'm still getting the
same error. We upgraded from CF 8.0.1 and it was the same IIS
configuration with virtual directories. The note that you point out from
the developer's guide says that "The componentPath value must be ... the
directory that contains the current page" which is the case with the code
that I originally posted because the cfc and calling cfm page reside in
the same directory. -
I'm having trouble with cfajaxproxy. I've copied demos and
they work as far as displaying the correct cfc invocation response
in the ajax debugger.
But - I can't seem to get setCallbackHandler to work. The
data never comes back. My callbackhandler never gets called.
Please help.
Shelplease help us help you: post your code!
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/ -
I am currently developing a CMS.
I am having a problem sending html code to a CFC using
cfajaxproxy in IE7. The code works perfect in Firefox 3
and Safari. The error that I get in IE 7 is the following:
Error: The system cannot locate the resource specified.
The CF8 server is updated with updater 1. I think it is a CF
Bug.
Here is a test page broken down to a very simple form:
http://cms.lbcc.edu/testephox.cfm
Here is the code:
<cfajaxproxy cfc="cmsadmin.components.webpage"
jsclassname="getpageOBJ">
<html>
<head>
<script language="JavaScript" type="text/javascript">
var submitform = function(){
res = document.testform.ta.value;
var catID = 5;
var editorContent = new getpageOBJ();
editorContent.savepage(catID,res);
</script>
</head>
<body>
<form action="" method="post" name="testform">
<textarea name="ta" cols="80" rows="30">
<table width="100%" border="0" cellpadding="0"
cellspacing="0" bgcolor="#000000" class="tablestylefooter">
<tr>
<td width="100%" valign="top" colspan="3"><img
src="
http://www.lbcc.edu/images/web_temp_images/spacer_top.gif"
width="100%" height="10" alt="" /></td>
</tr>
<tr>
<td colspan="3" width="100%">
<table width="100%" border="0" cellspacing="0"
cellpadding="3">
<tr>
<td width="33%" align="left" class="footer"><span
class="footertext1"><b>test</b></span><br
/> <span class="footertext2"> 49asdfdsaf East Carson
Street<br /> </span>
</td>
<td valign="top" width="33%" height="46">
<div align="center">
<span class="footertext3"><br />
ads </span><br /><a href="
http://acit.lbcc.edu/webcorner/index.cfm"
title="Web Standards" class="linkcolor1">Web
Standards</a></div>
</td> <td align="right" class="footer" width="33%"
> <div align="right"><span
class="footertext1"><b>adsfdsfsaf</b></span><br
/>
<span class="footertext2"> adsf adsfy<br />
Ladsf, CA 90806</span></div></td>
</tr>
</table>
</textarea>
</form>
<a href="javascript:void(0);"
onClick="javascript:submitform();">Save Page</a>
</body>
</html>
Any suggestions would be appreciated.
Thanks.
RonThanks to Raymond Camden I was able to get on the right path.
The cfajaxproxy was sending the editor information using
"GET". If you are sending information
through the cfajaxproxy you are limited using "GET". All I
had to do is add the following:
var editorContent = new getpageOBJ();
editorContent.setForm('testform');
editorContent.setHTTPMethod('POST');
editorContent.savepage(catID,res);
The setHTTPMethod('POST') worked perfectly!
Ron -
CFAJAXPROXY: "The specified CFC proxy could not be found."
{ColdFusion 8, latest, Windows.}
The following statement occurs (in an included CFM file):
<cfajaxproxy cfc="crv2_js" jsclassname="ServerProxy">
The "crv2_js.cfc" file is indeed located in the same directory. (If you request it at the same URL, and enter the administrator password, a nice formatted description of the library and its methods dutifully appears, so it is there...)
But the error is:
The specified CFC proxy could not be found.
The path to the CFC must be specified as a full path, or as a relative path from the current template, without the use of mappings.
Looking also on the Administrator screen, I confirm that the directory is not mapped.
Other, <cfinvoke> calls have been used to a sister CFC-library in the same directory without incident. So I am confident that the message that I am seeing is somehow bogus ... but I do not yet know what sort of "bogosity" it must be.Now here is something I didn't expect to see. When I turned on "extended error information" (or whatchamacallit...) I got this additional information in the displayed log:
The specified CFC proxy could not be found.
The path to the CFC must be specified as a full path, or as a relative path from the current template, without the use of mappings.
The error occurred in C:\Inetpub\wwwroot\NCPT\CRV2\cr_PrototypeManager.cfm: line 235
<cfgridcolumn
name="DefinitionIsLocked"
233 : header="Is In Use"
234 : type="boolean"
235 : select="no">
236 :
237 : </cfgrid>
(Ooh... formatted! Now ain't that slick!)
I took the liberty of pasting-in lines 231-232, which the debugging-output did not include. In fact, here is the entire block of code:
<cfgrid name="datagrid" pagesize="5" format="html" width="100%" height="200"
"cfc:proxy.GridSource_ReviewPrototypes({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{c fgridsortdirection},getPageSize())">
<cfgridcolumn
name="ID"
header="ID"
display="false" >
<cfgridcolumn
name="TemplateName"
header="Template Name" >
<cfgridcolumn
name="PrototypeClassName"
header="Prototype Class" >
<cfgridcolumn
name="Description"
header="Description">
<cfgridcolumn
name="Enabled"
header="Enabled"
type="boolean">
<cfgridcolumn
name="DefinitionIsLocked"
header="Is In Use"
type="boolean"
select="no">
</cfgrid>
So... why on earth would an error like that be showing up at a place like this? (Removing the "select='no'," on the wild-guess theory that it might be "the odd man out," as-expected had no useful effect.)
My hypothesis here is that the "failure location" actually has nothing to do with anything: this is simply the last clause in the CFGrid construct, and the computer is now trying to place a call to this function:
<cffunction name="GridSource_ReviewPrototypes" access="remote" returntype="any">
<cfargument name="page" required="yes">
<cfargument name="pageSize" required="yes">
<cfargument name="gridsortcolumn" required="yes">
<cfargument name="gridsortdirection" required="yes">
<cfargument name="customPageSize" required="no" default="0">
Uh huh... straight out of a demo.
I thought I had just-now discovered the problem, as I was writing this, because the "bind" expression had two additional parameters which are not listed in <cfargument> tags. But, much to my surprise, it didn't fix it.
To be absolutely complete in my description:
In an included header-file, we have: <cfajaxproxy cfc="crv2_js" jsclassname="ServerProxy">
On this (Windows) host, the file-name of the CFC file is "crcv2_js.cfc" and it is located in the same directory as both the cfm and the included cfm.
In the <head> portion of the main page, we have (in an in-line <script> tag):
var proxy = new ServerProxy();
proxy.setErrorHandler(showError);
proxy.setCallbackHandler(handleResult);
I'm starin' at this thing and starin' at this thing and everything I see is screamin' at me, "bogus!" 'Cept I know it can't be.
The generated page-source code includes the following, including a bit which I have highlighted in bold face. I don't know where that bit came from.
<script type="text/javascript">
ColdFusion.Ajax.importTag('CFAJAXPROXY');
</script>
<script type="text/javascript">
var _cf_crv2_js=ColdFusion.AjaxProxy.init(
'/CRV2/crv2_js.cfc','ServerProxy');
but it does seem plausible since the URL to the site-page (on case-insensitive Windows) is, indeed:
http://tlcapps/crv2/cr_PrototypeManager.cfm
and, again, if I type in "http://tlcapps/CRV2/crv2_js.cfc" and prove that I do know the proper ColdFusion admin-password, I get a nice pretty-printed description of this library and its methods... including the one I am trying to call. It does exist. -
Still having problem with cfdiv
Hi,
I pass in my variable with cfajaxproxy to sayHello_serverSide, but i need to return this to the page via cfdiv. My cfdiv tag bound to a cfm page which invokes the returnToDiv method.
The problem is the variable does not seem to pass from the sayHello_serverSide method to the returnToDiv method. How can I make #arguments.name# available to the returnToDiv method.
Thanks.
<cfcomponent output="true">
<cffunction name="sayHello_serverSide" access="remote" returntype="string" output="yes" >
<cfargument name="name" type="string" required="false" default="Nameless" >
<cfreturn #arguments.name# >
</cffunction>
<cffunction name="returnToDiv" returntype="string">
<cfinvoke method="sayHello_serverSide" returnvariable="myname" />
<cfreturn myname />
</cffunction>
</cfcomponent<cffunction name="returnToDiv" access="remote" returntype="string">
-
Hi guys.
I'm getting started with some ajax functions. so i had to look at cfajaxproxy.
It look as it is very cool function but i don't get it work.
I've got a directory with two files in it. cfAjaxProxy.cfm and proxy.cfc on the toplevel. There's no Application.cfc or something...
so i'm calling the proxy.cfc with
<cfajaxproxy cfc="proxy" jsclassname="proxy" />
but then appears an error
The specified CFC proxy could not be found.
The path to the CFC must be specified as a full path, or as a relative path from the current template, without the use of mappings.
The error occurred in D:\www2\cfajaxproxy\cfAjaxProxy.cfm: line 1
1 : <cfajaxproxy cfc="proxy" jsclassname="proxy" />
2 :
3 : <script>
I'm now on CF9.
I've googled around and read the reference a few times...
Sorry for my bad english...
regards.
MaertschHi, thanks for your reply.. i'll give my best.
i called proxy.cfc by the URL.
proxy
Component proxy
hierarchy:
WEB-INF.cftags.component
proxy
path:
D:\www2\cfajaxproxy\proxy.cfc
serializable:
Yes
properties:
methods:
reverseString, serverTime
So seems that everything works fine. you see the path is also correct (same directory).
Is this a problem with some mappings... I'm running on default Administrator setting and haven't mapped anything. -
Hi,
I love CF I really do, but when will Adobe optimize their JS
scripts and CSS etc??
I have CF8 and using the new cfwindow tag is more pain than
it's worth because it includes so many JS files and badly inserted
inline scripts or CSS. I would love to use it, but the page size
can start to get a little crazy.
Don't get me wrong, I love all this new stuff, but I would
like Adobe to concentrate a bit more on optimization with many of
CFs features - old and new, hopefully with a new release in the
future.
CF links to JS files that can be quite large, but since many
of these wont even be touched by its users, why not link to heavily
compressed versions instead - reducing white space etc and saving
bandwidth.
It's not a big deal for some, but on a site with hundreds of
thousands of impressions a day this can be a big problem.
What are your thoughts??
Thanks,
Mikey.Check out the CFAJAXIMPORT tag. The AJAX support in CF8 is
provided ala cart, so you can use as much or as little as you like,
mix and match your favorite frameworks, balance development speed
and functionality, etc.
1) First we have the CFAJAXPROXY and "Ajax Plumbing" -level
features which offer no UI components and simply make Ajax
development easier with JavaScript proxies for the remote methods
on a server side CFC, Ajax client side debugging, Adobe Spry,
support for Spry dataset binding, JSON, data marshalling, client
side data binding, etc.
2) Then we have the "full Monty" with the UI controls, etc,
powered by the Yahoo! UI Ajax toolkit and Jack Slocum's excellent
ExtJS Yahoo UI Toolkit add-in components, and our own Spry toolkit
plumbing, etc.
If you don't like #2 for any reason, you can always do Ajax
development using your favorite Ajax UI framework (jQuery, Dojo,
etc), but still use all the great "Ajax plumbing" productivity
features we've added to make developing in your favorite Ajax UI
framework super fast and easy. No prob.
We knew we couldn't make everybody happy with one fixed
feature set, so we broke it down into "use what you like, leave
what you don't" levels of Ajax integration.
Having said that, we did pay particular attention to the
download sizes for both levels of Ajax feature integration, and I
think you'll find that you can build a very svelte Ajax app (~51k
total download size, including data...about the size of a
medium-weight JPEG these days) using the Ajax plumbing feature set.
The CFAJAXIMPORT tag can help you fine tune what you want
downloaded as well.
Hope that helps clarify what we tried to do in CF8.
Damon -
I'm having problem when I run a code to make a CFAJAXPROXY,
the code is calling a cfc on a change of drop down to populate
another drop down, the proxy is using "POST". Now the problem, this
code runs perfect (super fast) on dev box (windows XP with IIS5),
when using same code on win2003 server with IIS6, the IE7 freeze
for few seconds until the other drop down get populated (BTW, it
only populate it with about 10 records).
ANY SOLUTION , CLUE, HOTFIX ....ETC.If you do a get to the CFC method with the variables in the
URL using your web browser, how quickly is this returning. If this
is taking the 10 seconds, then it's the server that is going slow
and not the client side.
ex:
http://domain.com/ws/mycfc.cfc?method=mymethod&var1=x&var2=3&returnformat=plain -
I am trying to implement some kind of a server listening for requests. The listener part of the app, is a daemon thread that listens for connections and instantiates a handling daemon thread once it gets some. However, my problem is that i must be able to kill the listening thread at the user's will (say via a sto button). I have done this via the Sun's proposed way, by testing a boolean flag in the loop, which is set to false when i wish to kill the thread. The problem with this thing is the following...
Once the thread starts excecuting, it will test the flag, find it true and enter the loop. At some point it will LOCK on the server socket waiting for connection. Unless some client actually connects, it will keep on listening indefinatelly whithought ever bothering to check for the flag again (no matter how many times you set the damn thing to false).
My question is this: Is there any real, non-theoretical, applied way to stop thread in java safely?
Thank you in advance,
LeftyThis was one solution from the socket programming forum, have you tried this??
public Thread MyThread extends Thread{
boolean active = true;
public void run(){
ss.setSoTimeout(90);
while (active){
try{
serverSocket = ss.accept();
catch (SocketTimeoutException ste){
// do nothing
// interrupt thread
public void deactivate(){
active = false;
// you gotta sleep for a time longer than the
// accept() timeout to make sure that timeout is finished.
try{
sleep(91);
}catch (InterruptedException ie){
interrupt();
} -
A problem with Threads and MMapi
I am tring to execute a class based on Game canvas.
The problem begin when I try to Play both a MIDI tone and to run an infinit Thread loop.
The MIDI tone "Stammers".
How to over come the problem?
Thanks in advance
Kobi
See Code example below:
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
public class MainScreenCanvas extends GameCanvas implements Runnable {
private MainMIDlet parent;
private boolean mTrucking = false;
Image imgBackgound = null;
int imgBackgoundX = 0, imgBackgoundY = 0;
Player player;
public MainScreenCanvas(MainMIDlet parent)
super(true);
this.parent = parent;
try
imgBackgound = Image.createImage("/images/area03_bkg0.png");
imgBackgoundX = this.getWidth() - imgBackgound.getWidth();
imgBackgoundY = this.getHeight() - imgBackgound.getHeight();
catch(Exception e)
System.out.println(e.getMessage());
* starts thread
public void start()
mTrucking = true;
Thread t = new Thread(this);
t.start();
* stops thread
public void stop()
mTrucking = false;
public void play()
try
InputStream is = getClass().getResourceAsStream("/sounds/scale.mid");
player = Manager.createPlayer(is, "audio/midi");
player.setLoopCount(-1);
player.prefetch();
player.start();
catch(Exception e)
System.out.println(e.getMessage());
public void run()
Graphics g = getGraphics();
play();
while (true)
tick();
input();
render(g);
* responsible for object movements
private void tick()
* response to key input
private void input()
int keyStates = getKeyStates();
if ((keyStates & LEFT_PRESSED) != 0)
imgBackgoundX++;
if (imgBackgoundX > 0)
imgBackgoundX = 0;
if ((keyStates & RIGHT_PRESSED) != 0)
imgBackgoundX--;
if (imgBackgoundX < this.getWidth() - imgBackgound.getWidth())
imgBackgoundX = this.getWidth() - imgBackgound.getWidth();
* Responsible for the drawing
* @param g
private void render(Graphics g)
g.drawImage(imgBackgound, imgBackgoundX, imgBackgoundY, Graphics.TOP | Graphics.LEFT);
this.flushGraphics();
}You can also try to provide a greater Priority to your player thread so that it gains the CPU time when ever it needs it and don't harm the playback.
However a loop in a Thread and that to an infinite loop is one kind of very bad programming, 'cuz the loop eats up most of your CPU time which in turn adds up more delays of the execution of other tasks (just as in your case it is the playback). By witting codes bit efficiently and planning out the architectural execution flow of the app before start writing the code helps solve these kind of issues.
You can go through [this simple tutorial|http://oreilly.com/catalog/expjava/excerpt/index.html] about Basics of Java and Threads to know more about threads.
Regds,
SD
N.B. And yes there are more articles and tutorials available but much of them targets the Java SE / EE, but if you want to read them here is [another great one straight from SUN|http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html] .
Edited by: find_suvro@SDN on 7 Nov, 2008 12:00 PM -
Hi all,
I would like to ask you for a help. I need to write a small program at my university. I started to write a midlet which function would be to countdown time for sports activities. I woul like to start a new thread - the one that counts down - and at the same time make the main thread sleep. After the "countdown" thread finishes, the main thread wakes up and waits for user input. The problem is that when the "countdown" thread finishes his work, I've got Uncaught exception java/lang/NullPointerException. error and the midlet halts.
Below you can find the code
import java.lang.*;
import java.util.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class intervals extends MIDlet implements CommandListener
public Display ekran;
private SweepCanvas sweeper;
private Form rundy;
private TextField round0, round1, round2, round3, round4, round5, round6, round7, round8;
private long czas,x;
private Command exitCommand;
private Command addRound;
private Command delRound;
private Command start;
private TextField repeat;
private Form odliczanie;
private Alert ostrz;
Licznik thread;
String test;
StringItem test1;
int parz,i,j,k;
static int l;
int ilrund;
int ilpowt;
Item sec;
long sec1;
public intervals()
rundy = new Form("Interwały sportowe");
exitCommand = new Command("Wyjście", Command.EXIT, 2);
addRound = new Command("Dodaj","Dodaj rundę", Command.ITEM,1);
delRound = new Command("Usuń","Usuń ostatnią rundę", Command.ITEM,1);
start = new Command("Start", Command.ITEM,1);
odliczanie = new Form("Odliczanie");
TextField dodaj(TextField kolej)
kolej=new TextField("Podaj czas (s) rundy "+parz,null, 4, TextField.NUMERIC);//stworzenie nowej instancji do wybierania czasu trwania rundy
if(rundy.size()==0)
rundy.insert(rundy.size(),kolej);
else
rundy.insert(rundy.size()-1, kolej);
return kolej;
void odliczanie(TextField round)
monitor m=new monitor();
k=Integer.parseInt(round.getString());
ekran.setCurrent(odliczanie);
thread=new Licznik(k,odliczanie);
thread.start();
ekran.setCurrent(rundy);
public void startApp()// throws MIDletStateChangeException
rundy.deleteAll();
repeat = new TextField("Podaj ilość powtórzeń",null,1,TextField.NUMERIC);
rundy.addCommand(addRound);
rundy.addCommand(exitCommand);
rundy.setCommandListener(this);
Canvas obrazek = new MyCanvas();
ekran = Display.getDisplay(this);
ekran.setCurrent(obrazek);
czas=System.currentTimeMillis();
while (System.currentTimeMillis()<czas+1000)
continue;
ekran.setCurrent(rundy);
public void pauseApp()
public void destroyApp(boolean unconditional)
notifyDestroyed();
public void commandAction(Command c, Displayable s)
if (c == exitCommand)
destroyApp(false);
notifyDestroyed();
else if(c==addRound)
if(rundy.size()==0)//Sprawdzenie ilości elementów w celu poprawnego wyświetlania liczby rund w formie
parz=1;
else
parz=rundy.size();
switch(parz)
case 1:
round0=dodaj(round0);break;
case 2:
round1=dodaj(round1);break;
case 3:
round2= dodaj(round2);break;
case 4:
round3=dodaj(round3);break;
case 5:
round4=dodaj(round4);break;
default:
ostrz=new Alert("Uwaga","Maksymalna liczba rund wynosi 9", null, AlertType.INFO);
ostrz.setTimeout(3000);
ekran.setCurrent(ostrz);
if(rundy.size()==1)
rundy.append(repeat);
rundy.addCommand(start);
rundy.addCommand(delRound);
else if(c==delRound)
if(rundy.size()!=0)
rundy.delete(rundy.size()-2);
if (rundy.size()==1)
rundy.deleteAll();
if(rundy.size()==0)
rundy.removeCommand(delRound);
rundy.removeCommand(start);
else if(c==start)
ilrund=rundy.size()-1;
if(this.repeat.size()>0)
ilpowt=Integer.parseInt(this.repeat.getString());
ekran = Display.getDisplay(this);
for (i=1; i<=ilpowt;i++)
odliczanie= new Form("Odliczanie");
for (j=0;j<ilrund;j++)
switch(j)
case 0:
odliczanie(round0);
break;
case 1:
odliczanie(round1);
break;
case 2:
odliczanie(round2);
break;
case 3:
odliczanie(round3);
break;
case 4:
odliczanie(round4);
break;
case 5:
odliczanie(round5);
break;
case 6:
odliczanie(round6);
break;
case 7:
odliczanie(round7);
break;
case 8:
odliczanie(round8);
break;
class Licznik extends Thread
int czas1,k;
Form forma;
monitor m;
public Licznik(int k,Form formap)
czas1=k;
forma=formap;
public synchronized void run()
while(czas1>0)
forma.deleteAll();
forma.append("Czas pozostały (s): "+czas1);
try{Thread.sleep(1000);} catch(InterruptedException e){e.printStackTrace();}
czas1--;
if(czas1<=0)
m.put();
}and monitor class
public class monitor
boolean busy=false;
synchronized void get()
if(!busy)
try
wait();
}catch(InterruptedException e){e.printStackTrace();}
notify();
synchronized void put()
if(busy)
try
wait();
}catch(InterruptedException e){e.printStackTrace();}
busy=true;
notify();
}Can anybody help me with this?Groovemaker,
Your Licznik class has a member m of type monitor, which has not been instantiated (in other words is null) hence, when calling m.put() you get NullPointerException. Please also mind, that using Thread.sleep(1000) is not an accurate way of measuring time.
If I may, please use recommended for Java class naming conventions - some of your names use lower case, while other don't which is confusing to the reader.
Daniel -
Problem with threads within applet
Hello,
I got an applet, inside this applet I have a singleton, inside this singleton I have a thread.
this thread is running in endless loop.
he is doing something and go to sleep on and on.
the problem is,
when I refresh my IE6 browser I see more than 1 thread.
for debug matter, I did the following things:
inside the thread, sysout every time he goes to sleep.
sysout in the singleton constructor.
sysout in the singleton destructor.
the output goes like this:
when refresh the page, the singleton constructor loading but not every refresh, sometimes I see the constructor output and sometimes I dont.
The thread inside the singleton is giving me the same output, sometime I see more than one thread at a time and sometimes I dont.
The destructor never works (no output there).
I don't understand what is going on.
someone can please shed some light?
thanks.
btw. I am working with JRE 1.1
this is very old and big applet and I can't convert it to something new.Ooops. sorry!
I did.
public void start() {
public void stop() {
public void destroy() {
try {
resetAll();
Configuration.closeConnection();
QuoteItem.closeConnection();
} finally {
try {
super.finalize();
} catch (Throwable e) {
e.printStackTrace();
} -
Problem with Threads and a static variable
I have a problem with the code below. I am yet to make sure that I understand the problem. Correct me if I am wrong please.
Code functionality:
A timer calls SetState every second. It sets the state and sets boolean variable "changed" to true. Then notifies a main process thread to check if the state changed to send a message.
The problem as far I understand is:
Assume the timer Thread calls SetState twice before the main process Thread runs. As a result, "changed" is set to true twice. However, since the main process is blocked twice during the two calls to SetState, when it runs it would have the two SetState timer threads blocked on its synchronized body. It will pass the first one, send the message and set "changed" to false since it was true. Now, it will pass the second thread, but here is the problem, "changed" is already set to false. As a result, it won't send the message even though it is supposed to.
Would you please let me know if my understanding is correct? If so, what would you propose to resolve the problem? Should I call wait some other or should I notify in a different way?
Thanks,
B.D.
Code:
private static volatile boolean bChanged = false;
private static Thread objMainProcess;
protected static void Init(){
objMainProcess = new Thread() {
public void run() {
while( objMainProcess == Thread.currentThread() ) {
GetState();
objMainProcess.setDaemon( true );
objMainProcess.start();
public static void initStatusTimer(){
if(objTimer == null)
objTimer = new javax.swing.Timer( 1000, new java.awt.event.ActionListener(){
public void actionPerformed( java.awt.event.ActionEvent evt){
SetState();
private static void SetState(){
if( objMainProcess == null ) return;
synchronized( objMainProcess ) {
bChanged = true;
try{
objMainProcess.notify();
}catch( IllegalMonitorStateException e ) {}
private static boolean GetState() {
if( objMainProcess == null ) return false;
synchronized( objMainProcess ) {
if( bChanged) {
SendMessage();
bChanged = false;
return true;
try {
objMainProcess.wait();
}catch( InterruptedException e ) {}
return false;
}Thanks DrClap for your reply. Everything you said is right. It is not easy to make them alternate since SetState() could be called from different places where the state could be anything else but a status message. Like a GREETING message for example. It is a handshaking message but not a status message.
Again as you said, There is a reason I can't call sendMessage() inside setState().
The only way I was able to do it is by having a counter of the number of notifies that have been called. Every time notify() is called a counter is incremented. Now instead of just checking if "changed" flag is true, I also check if notify counter is greater than zero. If both true, I send the message. If "changed" flag is false, I check again if the notify counter is greater than zero, I send the message. This way it works, but it is kind of a patch than a good design fix. I am yet to find a good solution.
Thanks,
B.D.
Maybe you are looking for
-
Creation of suspension line items for Subscription orders
hi , I am currently working on IS-Media project. I have a requirement that I need to create a suspension for all the line items available for the subscription orders. I mean I have to create a new line item for all the active line items of a s
-
Java error when execute SAP MII Workbench
Hi Experts, I getting the following error when I execute the SAP MII Workbench. I have the Java 1.6.0.23 on a Windows 7 64 bits. I tried the Java 64 bits version and had the same error. Any idea? Regards, Vinicius A fatal error has been detected by t
-
I want an answer urgent for this Error
Hi all I am using MS Access as a database In my JSP code when i used one query or many updates, that works fine. However, when i use two queries, it shows the following error. By the way, i tried to use different connections and the same connection a
-
Configuring the application server to use HTTP proxy server
Hi, I am trying to configure LiveCycle ES2 to access services over the internet and since my Livecycle server connects to internet through a Proxy server, I have referred to section 5.8.2 of LiveCycle install_weblogic.pdf that states the following: I
-
We had a power outage whilst I was using and uploading photos into iphoto. When I re opened iphoto I had lost all my photos but the last ones uploaded (5,500 ish photos). With Finder and time machine I have managed to get back all my photos up to Dec