Toolkit.getDefaultToolkit().getScreenSize() Thread Never Ends
Consider two "Hello World" programs. On the second program add the
following call:
Toolkit.getDefaultToolkit().getScreenSize();
The first program after executing all of the statements in its "main"
method will exit. The second program after executing all of its
statements will not. For the second program System.exit(0) must be
called. Why is this?
Jason
Well a Java chat room visit provided me with the information that:
A call to Toolkit starts an event thread that doesn't die, so that
System.exit (0) must be called.
I still don't know if this is a bug and/or if there is a way to kill
that thread after I am done using the Toolkit...
Jason
Similar Messages
-
Toolkit.getDefaultToolkit() in Java service never returns on Windows
I'm stumped by this problem. It appears to be specific to a single machine as I can reproduce it reliably there but not on other machines. I'm hoping someone has some thoughts on what could be going on.
Here's the scenario:
I have Tomcat 5 running as a service on a new installed Windows 2000 Server with up to date service packs and j2sdk1.4.2_06. The service is configure to run headless.
I have a webapp that performs simple image transformations using AWT and Java2D. Any invocation of Toolkit.getDefaultToolkit() never returns. The thread just sits there consuming no CPU and does not throw an exception. I've narrowed it further to a call to new sun.awt.windows.WToolkit() in getToolKit(). sun.awt.windows.WToolkit is the value of the system property awt.toolkit.
I can reproduce this exact behavior in a different scenario: the server is running sshd on cygwin. If I ssh to the server and run the following class, it also hangs at new sun.awt.windows.WToolkit().
public class ToolkitTester
public static void main(String[] args)
System.out.println("awt.toolkit = " + System.getProperty("awt.toolkit"));
System.out.print("Invoking: new sun.awt.windows.WToolkit()... ");
new sun.awt.windows.WToolkit();
System.out.println("done.");
}Running this same class from a shell on the server works just fine.
I have tried j2sdk1.4.2_03 and jdk1.5 with the same results. I've replicated this second scenario (logging in over ssh) on another Windows 2000 server and do not see this behavior.
Any thoughts?
AlonOkay. Here's the fix...
The 'no video card' comment was actually pretty close. The issue appears to be with DirectDraw support. We found this by watching regmon as the testing code ran. Installing a new video driver may have addressed this but so does disabling using DirectDraw as described here:
http://java.sun.com/products/java-media/2D/forDevelopers/java2dfaq.html#dither
java -Dsun.java2d.noddraw=true
Wow. Weird one.
Alon -
Toolkit.getDefaultToolkit and Dimension = getScreenSize() is too big
So I normally use
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension dim = tk.getScreenSize();but in my application it was a little bit bigger than it should be, which in my case "1920x1600" isn't that big a deal.
However I made something for my mom, and when she used it on her tiny Dell 10" laptop it was REALLY cut off.
My Scene's size was set to dim.getWidth() and Height, so it should fill correctly right?
Should I NOT be using AWT's Toolkit? Is there something in FX I am missing?
Thanks all!!
~KZSo the rectangle is just to get the bounds of my screen right?Yes.
It has nothing to do with actually creating it right?Right. Rectangle2D is similar to java.awt.Dimension.
Note that there is also javafx.scene.shape.Rectangle which is a shape.
Do I use the rectangle's Height/Width to set up my Scene's info? You can use it to set scene size. Let’s say you want to create a scene with a screen size:
javafx.stage.Screen screen = Screen.getPrimary();
javafx.geometry.Rectangle2D rectangle2D = screen.getVisualBounds();
Scene scene = new Scene(root, rectangle2D.getWidth(), rectangle2D.getHeight()); -
Toolkit.getDefaultToolkit().getScreenResolution()
Hi I called Toolkit.getDefaultToolkit().getScreenResolution() to get my monitor screen resolution. It returns 96 dpi.
But as i check my monitor hardware specs, I found it was different. My monitor is 15.1 inch MultiSync LCD1530v and the hardware specs is found at http://www.necmitsubishi.com/products/home/product.cfm?productid=145&cfid=2239759&cftoken=98264266
It can can found that the resolution is 0.3 mm dot pitch, which turns out to be 1/0.03 * 2.54=84.8 dpi. I am a bit confused by this. Can someone help me in answering the following question?
1. what is the link between 96dpi in Toolkit and 0.3mm in hardware specs? Can one derive one from another? Thanks!I have a 19 inch monitor and I too get 96 dpi. Is there something wrong with getScreenResolution()?
import java.awt.*;
public class TestMethods
public TestMethods()
public static void main(String[] args)
TestMethods testMethods1 = new TestMethods();
Toolkit toolkit= Toolkit.getDefaultToolkit();
Dimension screenSize= toolkit.getScreenSize();
int screenResolution= toolkit.getScreenResolution();
System.out.println("Screen size: " +screenSize);
System.out.println("Screen Resolution: " +screenResolution);
ran it 3 times and got
1600 X 1200
96
1280 X 1024
96
640 X 480
96
What's up with that? -
Java.lang.NoClassDefFoundError Toolkit.getDefaultToolkit
hi all
i got this error in a servlet.
i wrote it on my computer with no errors but, when i moved and executed it on a linux machine it doesn't work:
java.lang.NoClassDefFoundError at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:703)
at counter.count.createCounter(count.java:245)
the code is
images=Toolkit.getDefaultToolkit().getImage(imageSrc);
i think that the jdk version is the same on both the computers (1.4.0 or higher), and the code is the same!
why have i this problem
thanx
sandrohi rajesh
you don't know how i'm happy to see your answers!
i'm so desperate with this problem!
as you asked to me, this is the full stack trace that tomcat prints when i call my servlet:
javax.servlet.ServletException: Servlet execution threw an exception
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
at java.lang.Thread.run(Thread.java:536)
root cause
java.lang.NoClassDefFoundError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:130)
at java.awt.Toolkit$2.run(Toolkit.java:712)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:703)
at counter.count.createCounter(count.java:231)
at counter.count.processRequest(count.java:176)
at counter.count.doGet(count.java:187)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
at java.lang.Thread.run(Thread.java:536)
i don't know if there is some environment variable set up in a different way from my system (w2k) to the real server system (linux), also because i installed the jdk (1.4.0 on windows) without setting anything
if can help i'll post you soon the version of tomcat/jdk used by linux
thanx a lot
sandro -
Hi,
I'm developing -fixing somebody application- a SuperWaba application. SuperWaba is a poor minor release of Java Runtime. I'm transforming SQL Scripts into PDB files -i hate PDB files.
I make a Class that extends MainWindow that is called by Waba Applet. Waba Applet extends Java Applet -I hope so. When I run my class from the shell (cmd, over a Windows XP), an Applet Window appears and execute without erros my script transforming a SQL script in one or multiple pdb files (depending number of create sentences).
But, when i call my script from a PHP Script -i really hate this app, PHP + Java + ASP + Visual Basic ... can you believe it ? - the PHP Script launch Java, but Java app never ends blocking my PHP script. I think there is a problem in Applet Window creation, because there is no window or display to launch the app.
There is a way to run an Applet in background with no visualization ?
THX 4 Ur HELPi really appreciate your help but i forgot to explain the problem
First, i decide to create a simple Java App that uses the PDBDriver JAR, but the #~"$%" Jar uses something from the Applet. When I run my class it launch these error.
java.lang.NullPointerException
at java.applet.Applet.getCodeBase(Unknown Source)
at waba.applet.JavaBridge.openOutputStream(JavaBridge.java:533)
at waba.applet.JavaBridge.writeBytes(JavaBridge.java:588)
at waba.io.NativeMethods4JDK.catalogClose(NativeMethods4JDK.java:824)
at waba.io.NativeMethods4JDK$CatalogBag.finalize(NativeMethods4JDK.java: 674)
at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)
at java.lang.ref.Finalizer.runFinalizer(Unknown Source)
at java.lang.ref.Finalizer.access$100(Unknown Source)
at java.lang.ref.Finalizer$3.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
#2- url: file://localhost/nullfile.pdb
found under localhost: file://localhost/nullfile.pdb
file not found -
I have had thi issue in the past and
TAC provided me a patch under bug id CSCtd49439 but I seem to
have the same problem again
I have this acquisition runnng since the 9th and it as never stopped and I don't know why it is showing 45855 hosts, the most we have less than 10000 hosts. Can anyone tell me what cuould be wrong with my server?
I'm running LMS3.2 on Solaris 10.
Acquisition status Running
Acquisition type Major
Acquisition start time 09 Oct 2010, 05:00:00 EDT
Last Acquisition end time 08 Oct 2010, 07:44:01 EDT
Number of acquisitions 1155
Number of host entries 45855
Number of duplicate MAC 21341
Number of duplicate IP 89
Number of CCM hosts 0
Number of IP phone entries 0
Last campus data collection completed at 11 Oct 2010, 12:14:33 EDT
Campus data collection status IdleA never-ending UT acquisition is not the same as the problem described by CSCtd49439. That would also not account for an inflated number of end hosts. Without knowing the exact details of the end hosts, I do know we had an old bug in Campus 4.x where UT would generate perpetual duplicates. This was fixed in 4.0.11, but one would need to reinitialize the ANI database to remove the duplicates. If this is an upgrade from LMS 2.6, then perhaps you still have old, stale data. Running this command would fix that:
NMSROOT/bin/perl NMSROOT/campus/bin/reintdb.pl -ut
As for the never-ending UT, check to see if the UTMajorAcquisition process is still running. If so, contact TAC, and they can walk you through the process to get a thread dump from this process. That will help identify what the process is doing and whether or not this is some kind of deadlock, or a configuration issue. -
Hi,
Well I had a few minutes on my hand and decided to build a simple socket application that handles a browser request with a �hello�. Then I decided to complicate that a little and to actually send back what I receive. However the while loop that checked the input from the browser never ends (that is I never get a �1 from inputStream.read() method).
Could someone please explain me why this happens? And how this could be solved? I mean how to detect that the request is over and it is time to respond. (In other words how can I base my response according to the request if I never know when the request is over!).
Here is the code I used import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
public class Test7 {
public static void main(String[] args) {
try {
ServerSocket serverSocket = new ServerSocket(9989);
while(true){
Socket socket = serverSocket.accept();
new Thread(new SimpleHttpHandler(socket)).run();
catch (Exception e) {
e.printStackTrace();
class SimpleHttpHandler implements Runnable{
private Socket client;
public SimpleHttpHandler(Socket client){
this.client = client;
public void run(){
try{
BufferedOutputStream outputStream = new BufferedOutputStream(
this.client.getOutputStream()
BufferedInputStream inputStream = new BufferedInputStream(
this.client.getInputStream()
int in = 0;
while((in = inputStream.read()) != -1){
System.out.print((char)in);
outputStream.write(in);
outputStream.close();
outputStream.flush();
catch(Exception e){
e.printStackTrace();
Regards,
Sim085So you can't read RFC but can read forums? :)Can you imagine reading documentation about something by continuously minimizing and maximizing the browser window? (which I do when at work so to attract less attention) :)
Well if you want simplest way then just send header,
data and close connection that's enough.Thanks :) I understand that now :)
@bsamperi & [email protected]
The code I provided above was not correct. I fixed it and posted it again just in case someone else comes across this post. As already said this was not what I had in mind to do in the first place, but it was fun :) Anyways here is the working code! (Although naturally not good for anything)import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class Test7 {
public static void main(String[] args) {
try {
ServerSocket serverSocket = new ServerSocket(8871);
while(true){
System.out.println("Waiting for request");
Socket socket = serverSocket.accept();
new Thread(new SimpleHttpHandler(socket)).run();
catch (Exception e) {
e.printStackTrace();
class SimpleHttpHandler implements Runnable{
private final static String CLRF = "\r\n";
private Socket client;
private BufferedWriter writer;
private BufferedReader reader;
public SimpleHttpHandler(Socket client){
this.client = client;
public void run(){
try{
this.writer = new BufferedWriter(
new OutputStreamWriter(
this.client.getOutputStream()
this.reader = new BufferedReader(
new InputStreamReader(
this.client.getInputStream()
System.out.println("-- IN --\n" + this.read() + "\n");
System.out.println("-- OUT --\n" + this.write("Thank You"));
this.writer.close();
this.reader.close();
this.client.close();
System.out.println("Completed response");
System.out.println("--------------------\n");
catch(Exception e){
e.printStackTrace();
private String read() throws IOException{
String in = "";
StringBuffer buffer = new StringBuffer();
while(!(in = this.reader.readLine()).trim().equals("")){
buffer.append(in + "\n");
return buffer.toString();
private String write(String out) throws IOException{
StringBuffer buffer = new StringBuffer();
buffer.append("HTTP/1.0 200 OK" + CLRF);
buffer.append("Content-Type: text/html" + CLRF);
buffer.append(CLRF);
buffer.append(out);
buffer.append(CLRF);
writer.write(buffer.toString());
return buffer.toString();
}The output of this code is: Waiting for request
-- IN --
GET / HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/vnd.ms-powerpoint, application/vnd.ms-excel,
application/msword, application/x-shockwave-flash, */*
Accept-Language: en-us
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2;
.NET CLR 1.1.4322; .NET CLR 2.0.50727)
Host: localhost:8871
Connection: Keep-Alive
-- OUT --
HTTP/1.0 200 OK
Content-Type: text/html
Thank You
Completed response
Waiting for request
-- IN --
GET /favicon.ico HTTP/1.1
Accept: */*
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2;
.NET CLR 1.1.4322; .NET CLR 2.0.50727)
Host: localhost:8871
Connection: Keep-Alive
-- OUT --
HTTP/1.0 200 OK
Content-Type: text/html
Thank You
Completed response
Waiting for request
...Which shows that this application will handle any web request with a �Thank You� since I am not basing the response on the request. However that should not be hard once the request and response are handled ok.
Thank to both of you for your help :)
Regards,
Sim085 -
InstallShield Wizard never ends under Solaris !
Hi
I am launching ./solaris_livecycle8_setup.bin under a new path on a same machine as my other Es installation.
The Installshield wizard never ends
This must be an issue with some temporary files of the previous separate install
But I can't find any files in /var/tmp or /opt/adobe
How can I extract nice adobe install files to luanch my install ?
Regards
ChrisA never-ending UT acquisition is not the same as the problem described by CSCtd49439. That would also not account for an inflated number of end hosts. Without knowing the exact details of the end hosts, I do know we had an old bug in Campus 4.x where UT would generate perpetual duplicates. This was fixed in 4.0.11, but one would need to reinitialize the ANI database to remove the duplicates. If this is an upgrade from LMS 2.6, then perhaps you still have old, stale data. Running this command would fix that:
NMSROOT/bin/perl NMSROOT/campus/bin/reintdb.pl -ut
As for the never-ending UT, check to see if the UTMajorAcquisition process is still running. If so, contact TAC, and they can walk you through the process to get a thread dump from this process. That will help identify what the process is doing and whether or not this is some kind of deadlock, or a configuration issue. -
Launching a never ending vi in sequence
Hi!
I have a vi that can basically be represented by a while loop that never stops until i press a button.
I want to load and run this vi from a sequence without it hanging up that sequence.
Also, at the end of the sequence it would be great if it could end the loop in the vi.
For this last part I made the vi read out a variable in my locals and stop the loop as soon as it is a certain value.
(I think this is a good solution, but any suggestions are of course welcome )
For being able to run the rest of the sequence, even though the vi never ends, I was less successful.
I tried putting the vi in a subsequence and then running that subsequence in a different thread.
However, stepping through the main sequence, it does steps over the call of the subsequence,
but then the main sequence still freezes until i stop the loop in my vi.
What am i doing wrong exactly? Any help would be much appreciated!
Solved!
Go to Solution.Run Asynchronous VI basically uses a sequence call module with the "New Thread" option, but I don't think it does much more than that. I think you still have to do ExternallySuspended and/or Termination monitor in your vi. At any rate, I recommend against using Run asynchronous vi as there have been issues with using that step type (confusion over what passing ThisContext means for the most part). See the following link for more details about the issues with Run asynchronous vi if you are interested:
http://forums.ni.com/ni/board/message?board.id=330&message.id=28101&query.id=753835#M28101
As far as termination monitor not detecting whether or not the original thread has completed normally, that is not its purpose and not always what a user might want. For example, you might have a worker thread that you want to keep running even after the thread that launched it completes. There might even be more than two threads in the execution and the execution technically isn't complete until all threads are done, including the asynchronous ones. The purpose of the termination monitor is to give the code module a way to detect when the user is requesting a terminate or abort so that it can return and allow the execution to terminate or abort normally (an execution cannot terminate or abort while a code module is still running).
Like you are suggesting, you can probably pass in the original caller's thread as a parameter to the asynchronous sequence and your VI and call Thread.WaitForEnd on it with a 0 ms timeout to check if it's done in your loop. You need to make sure that you unchecked the "Automatically Wait for the Thread to Complete at the End of the Current Sequence" setting on the advanced panel of your sequence call step though or your threads will both be waiting for each other and never complete. Also the sequence view of the execution is likely to switch to your asynchrous thread at the end because it will be the last thread running, so if you don't want that you should probably just go with passing a boolean variable instead and leave the setting "Automatically Wait for the Thread to Complete at the End of the Current
Sequence" checked. Do not ever pass ThisContext from one thread to another though as that is the source of the problems people are having with Run VI Asynchronously.
Hope this helps,
-Doug -
Dropped database in a never-ending app
Hello,
I have an application which processes all the time by implementing a never-ending loop and a sleep at a given interval. It accesses the database to retrieve, insert and update data throughout the entire process. I have created a connection pool that contains a configurable number of connections (for any future multi-threading) that will be retrieved to complete the SQL transaction and released when it no longer needs it. The list of connections is decreased when I access the pool and increased when the connection is released. My concern is that I would like to detect when the DB has been dropped and brought back up without having to restart my app. The first way to detect it would be to check the connection object when it is used, but I am not sure if that is the way to do it correctly. Does it fail when I create the preparedStatement or when I run executeQuery or executeUpdate? What is the best way to detect whether I need to re-create my pool of connections?
I appreciate your feedback.
Thank youIt will fail when you try to open the connection. If for example you are using a JNDI DataSource when you call the DataSource.getConnection() method it will throw a SQLException with the correct code and message for the database vendor.
That said, I wouldn't do it the way you're doing it. By holding an open connection, you're pirating a connection resource that the DB may need for something else, or another app might need and in my opinion it's just bad design.
I would recommend opening the connection at the beginning of the method where you are doing the data access and then closing it (along with all of the other database resources before leaving that method. A general code pattern would look like this.
public void getSomeInformation(){
String sql = "SELECT something FROM somewhere" ;
try{
// initialize the connection
// initialize the statement object
// prepare whatever parameters
// execute the statement
// make sure you got some results and process accordingly
catch(SQLException e){
// handle any exceptions that might come up
finally{
// close the result set
// close the statement
// close the connection
// set all of the above to null to mark them for GC
}Some of this may seem like overkill, but that's a feeling that goes away when you've had your application spin into the ground because you accidentally left database resources open and killed the database and the application server.
Yes, there's a little overhead in terms of getting the connection, but it's a delay that my customers have never complained about in the face of the abject reliability of making sure that the house is clean and orderly all the time. -
A : Image source = Toolkit.getDefaultToolkit().getImage("C:/aa.jpg");
B : Image source = Toolkit.getDefaultToolkit().getImage("");
generally, B may be null. but it is not null.
so I look at "javax.swing.ImageIcon" class :
<Part of ImageIcon source>
public ImageIcon(String filename, String description) {
image = Toolkit.getDefaultToolkit().getImage(filename);
if (image == null) { //This code is invaild.
return; //never return.
this.filename = filename;
this.description = description;
loadImage(image);
Do you thinking it?
Bug?getimage may not return null in the current implementation but they wanted maybe get sure that no nullpointerexception occures.
it's not a bug - it's a feature :-) -
A never ending multiplayer game?
Hi
I want to make a 2d spaceship multiplayer game (applet). The game should have lots of human controlled spaceships (and maybe some computer controlled spaceships if there are no human players). Each time a new user starts a game in its web browser, a new spaceship will appear in the game. The user will play until his spaceship is shot by another player. A shot spaceship will disappear from the game, and the player may choose to start a new game with a new spaceship. But the game on the server should never end. Each user will play in the same game on the server (but there may be a maximum number of players).
Is it possible to make a game that never ends? Which requirements apply to the server? Is it possible to use a normal web server (you have only FTP access to the server computer)?this is a fast extract from my files, when you run Gclient the server will be launched and 2 clients will be opend, the red boxes are players
using the mouse you move the box, the change of location is propagate thru the server.
Server
import java.io.*;
import java.net.*;
import java.util.*;
public class Gserver
private int players = 0;
private Vector ones = new Vector();
public Gserver()
ServerSocket servS;
Socket clnt;
try
servS = new ServerSocket(4444);
System.out.println("Server Ready on port: 4444");
while(true)
clnt = servS.accept();
System.out.println(""+clnt);
One one = new One(clnt);
one.start();
catch (IOException ex) {System.out.println(""+ex);}
public void sendToAll(String s)
for (int i=0; i < ones.size(); i++)
One one = (One)ones.get(i);
one.write(s);
public void sendToOne(One me)
for (int i=0; i < ones.size(); i++)
One one = (One)ones.get(i);
me.write(one.data);
public class One extends Thread
private Socket socket;
private BufferedReader in;
private PrintStream out;
public String data;
public One(Socket socket)
this.socket = socket;
public void run()
try
out = new PrintStream(socket.getOutputStream());
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
ones.add(this);
players++;
int x = players*30-25;
data = "P"+players+","+x+","+x+",";
sendToAll(data);
sendToOne(this);
while ((data = in.readLine()) != null)
sendToAll(data);
catch (IOException e) {System.out.println("one!!"+e);}
close();
ones.remove(this);
public void write(String s)
if (out != null)
out.println(s);
out.flush();
public void close()
if (socket == null) return;
try
if (socket != null) socket.close();
if (in != null) in.close();
if (out != null) out.close();
catch (IOException e){}
socket = null;
in = null;
out = null;
public static void main (String[] args)
new Gserver();
client GUI
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.event.*;
import java.util.*;
public class Gclient extends JFrame implements KeyListener
private Component me;
private Container co;
private Gsocket socket;
public Gclient()
super("Glient");
setBounds(1,1,500,200);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent ev)
if (socket != null) socket.close();
dispose();
System.exit(0);
co = (Container)getContentPane();
co.setLayout(null);
co.setBackground(Color.black);
addKeyListener(this);
requestFocus();
setVisible(true);
if (socket == null)
socket = new Gsocket(this);
if (!socket.isConnected())
dispose();
System.exit(0);
else socket.start();
public void keyTyped(KeyEvent ke){}
public void keyPressed(KeyEvent ke)
int kc = ke.getKeyCode();
if (me == null) return;
Point o = me.getLocation();
Point p = me.getLocation();
if (kc == 40) p.y++;
if (kc == 39) p.x++;
if (kc == 38) p.y--;
if (kc == 37) p.x--;
if (!p.equals(o)) socket.write(me.getName()+","+p.x+","+p.y+",");
public void keyReleased(KeyEvent ke){}
public void go(String s)
StringTokenizer tokn = new StringTokenizer(s.trim(),",");
String p = tokn.nextToken();
int x = 0;
int y = 0;
try
x = Integer.parseInt(tokn.nextToken());
y = Integer.parseInt(tokn.nextToken());
catch(NumberFormatException e){}
Component com = null;
for (int i=0; i < co.getComponentCount(); i++)
if (co.getComponent(i).getName().equals(p)) com = co.getComponent(i);
if (com == null)
JLabel l = new JLabel(p);
co.add(l);
l.setName(p);
l.setOpaque(true);
l.setBackground(Color.red);
l.setHorizontalAlignment(SwingConstants.CENTER);
com = l;
co.validate();
if (me == null)
me=l;
setTitle(p);
com.setLocation(x,y);
co.repaint();
public static void main (String[] args)
Thread t = new Thread()
public void run()
new Gserver();
t.start();
Gclient a = new Gclient();
Gclient b = new Gclient();
b.setLocation(b.getX(),b.getY()+220);
client socket
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
import java.net.*;
import java.io.*;
public class Gsocket extends Thread
private Gclient client;
public String host;// = "10.20.2.58";
private int port = 4444;
private Socket socket;
private PrintStream out;
private BufferedReader in;
public Gsocket(Gclient client)
this.client = client;
port = 4444;
try
InetAddress ia = InetAddress.getLocalHost();
host = ia.getHostName();
catch (UnknownHostException ex)
try
socket = new Socket(host,port);
out = new PrintStream(socket.getOutputStream());
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
catch(IOException ex)
socket = null;
public boolean isConnected()
if (socket == null) return(false);
else return(true);
public void run()
try
String data;
while ((data = in.readLine()) != null)
client.go(data);
catch(IOException ex)
close();
public void write(String s)
out.println(s);
public void close()
try
if (socket != null) socket.close();
if (in != null) in.close();
if (out != null) out.close();
catch (IOException e){}
socket = null;
in = null;
out = null;
}Noah -
FCPX never ending transcoding after Mavericks?
Hello folks,
Saw some of the other threads about problems with FCPX and Mavericks. Fortunately, everything has been fine for me... up to this point. I didn't see this discussed yet so I figured I'd post my issue in it's own thread.
I've been trying to import some files (AVCHD) as usual for ongoing projects. I copy the files and transcode them to optimized media. Never had a problem before. It seems to copy all the files fine, but seemingly never stops transcoding. I've been trying to import two different projects... about 4-5 hours of footage each... and it's been two days now and the transcoding never ends! Typically one such project takes about real time to import and transcode (4-5 hours, if not faster, never really timed it). I'd begin an export in the morning and come back after lunch and it would always be done.
That is no longer the case it seems.
Has anyone else experience the same issue? I just installed any and all updates available (nothing for FCPX however), restarted my computer and FCPX, and am trying again. Hopefully the footage ingests fine this time. But for the sake of losing more time and getting more frustrated, I'm hoping someone out there has a solution to this in the event the same problem persists for me.
Any feedback would be appreciated.
MattHi Russ,
Thanks for taking the time to respond. You've been extremely helpful in the past! As an update... I started the import around 7pm last night (EST). This morning, at 5am, it was still importing and transcoding... but it looked like it was at least working. After restarting last night, I tried to import and transcode a single short clip before doing the full import and that was easily successful.
When I get to the import prompt, I only check off "Copy files to Final Cut Events folder" and "Create optimized media". This workflow has been great for me. I turn off background rendering and don't even render 2 hour long projects with heavily edited footage before exporting to m4v master files (which turn out just fine without the rendering). That's beside the point though.
Back on track, when I open the Background Tasks, of course the transcoding is going. The Importing Media is stuck on 99%. Not sure if that's normal or not... never really paid attention to that in the past. The Rendering says it's creating audio waveforms. Again, not sure if that's normal or not.
In Activity Monitor, I might have found a problem. It seems FCPX is only using around 0.5% of CPU during the import. No other program is running really except for Activity Monitor, which would leapfrog FCPX in how much of the CPU it's using at time. At the bottom, it says my computer is around 98-99% idle! That all raises an eyebrow to say the least. I'm not a computer whiz when it comes to the technical aspect of how my system might be performing and I have admittedly not tried an import on another machine yet (I have three iMac's). So it may just be an issue with this one machine.
It's a 2011 model year running a 2.93 quad, i7. At least I'm pretty sure of that. I'm on a corporate event now typing away from another one of my iMac's and won't even know if the import and transcoding back at home is successful until I get back in tonight around 6:30 or so.
Even if it is, there's definitely something going on with how long it's taking. What's typically a 4-5 hour process (est) was still ingesting 10 hours later. -
My FaceTime doesn't work... I would call a person, they would accept, and then I would be stuck in a never ending "connecting".. And this problem has been according with not just my ipad, but with other people's iDevices that I know.
-My wifi connection is running strong
-All the devices run the same version of iOSTry this - Reset the iPad by holding down on the Sleep and Home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons. (This is equivalent to rebooting your computer.) No data/files will be erased. http://support.apple.com/kb/ht1430
Using FaceTime http://support.apple.com/kb/ht4319
Troubleshooting FaceTime http://support.apple.com/kb/TS3367
The Complete Guide to FaceTime + iMessage: Setup, Use, and Troubleshooting
http://tinyurl.com/a7odey8
Troubleshooting FaceTime and iMessage activation
http://support.apple.com/kb/TS4268
iOS: FaceTime is 'Unable to verify email because it is in use'
http://support.apple.com/kb/TS3510
Using FaceTime and iMessage behind a firewall
http://support.apple.com/kb/HT4245
iOS: About Messages
http://support.apple.com/kb/HT3529
Set up iMessage
http://www.apple.com/ca/ios/messages/
iOS and OS X: Link your phone number and Apple ID for use with FaceTime and iMessage
http://support.apple.com/kb/HT5538
How to Set Up & Use iMessage on iPhone, iPad, & iPod touch with iOS
http://osxdaily.com/2011/10/18/set-up-imessage-on-iphone-ipad-ipod-touch-with-io s-5/
Set Up Alert Sounds
http://www.quepublishing.com/articles/article.aspx?p=1873027&seqNum=3
Extra FaceTime IDs
http://tinyurl.com/k683gr4
Troubleshooting Messages
http://support.apple.com/kb/TS2755
Troubleshooting iMessage Issues: Some Useful Tips You Should Try
http://www.igeeksblog.com/troubleshooting-imessage-issues/
Setting Up Multiple iOS Devices for iMessage and Facetime
http://macmost.com/setting-up-multiple-ios-devices-for-messages-and-facetime.htm l
FaceTime and iMessage not accepting Apple ID password
http://www.ilounge.com/index.php/articles/comments/facetime-and-imessage-not-acc epting-apple-id-password/
Fix Can’t Sign Into FaceTime or iMessage iOS 7
http://ipadtutr.com/fix-login-facetime-imessage-ios-7/
FaceTime, Game Center, Messages: Troubleshooting sign in issues
http://support.apple.com/kb/TS3970
Unable to use FaceTime and iMessage with my apple ID
https://discussions.apple.com/thread/4649373?tstart=90
iOS 7 allows you to block phone numbers or e-mail addresses from contacting you via the Phone, FaceTime, or Messages
http://howto.cnet.com/8301-11310_39-57602643-285/you-can-block-people-from-conta cting-you-on-ios-7/
How to Block Someone on FaceTime
http://www.ehow.com/how_10033185_block-someone-facetime.html
My Facetime Doesn't Ring
https://discussions.apple.com/message/19087457#19087457
How to watch FaceTime calls on the big screen with Apple TV
http://www.imore.com/daily-tip-ios-5-airplay-mirroring-facetime
Send an iMessage as a Text Message Instead with a Quick Tap & Hold
http://osxdaily.com/2012/11/18/send-imessage-as-text-message/
To send messages to non-Apple devices, check out the TextFree app https://itunes.apple.com/us/app/text-free-textfree-sms-real/id399355755?mt=8
How to Send SMS from iPad
http://www.iskysoft.com/apple-ipad/send-sms-from-ipad.html
How to Receive SMS Messages on an iPad
http://yourbusiness.azcentral.com/receive-sms-messages-ipad-16776.html
Apps for Texting http://appadvice.com/appguides/show/apps-for-texting
You can check the status of the FaceTime/iMessage servers at this link.
http://www.apple.com/support/systemstatus/
Cheers, Tom
Maybe you are looking for
-
Bridge corrupts jpg metadata when applying metadata template (no preview in Finder)
Hi, Since a short while I found that applying one of my metadata templates (copyright etc.) to .jpgs in Adobe Bridge CC corrupts the metadata. What's seen is that the preview thumbnails in Finder disappear (change to jpg-logo), and there's no other w
-
Can't view PDFs over 500 kb in Chrome and MSIE, download as corrupted
I have Adobe Reader XI installed on a PC running Windows 7. I have it set as the pdf viewer for both Chrome and Internet Explorer. In either browser, when I try to view a pdf that is greater than 500 kb in size, it won't open and I get an error messa
-
Where can I find Red 4k clips to download?
Subject line pretty much sums it up. I know that they will be pretty large files, but I'd really like to play with some native Red 4k footage using CS5 and I don't have access to a Red 4k camera. The longer the duration, the better, and each clip nee
-
Java programming - Runtime class
hi I am not able to copy a file using Runtime class in java.lang i have used Runtime rt = Runtime.getRuntime(); Process pr = rt.exec("copy c:/venk1/pmrpay.jar F:/"); pr.waitFor(); when running the program i am getting this error message: create proce
-
LIC-EXP-RMS Expressway Rich Media Session I am planning to implement VPN less jabber feature, should i need to order RMS license can anybody advice me.