Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (761)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (845)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2]
  ignore  |  Print  
  Poor performance with JFileChooser  (Read 10833 times)
0 Members and 1 Guest are viewing this topic.
Offline BoBear2681

JGO Coder


Medals: 19



« Reply #30 - Posted 2014-10-15 22:53:47 »

Something that can cause random hangs in windows filesystems is attempting to access floppy drives, CD drives, or network drives that don't exist. Domain-related woes especially. You might want to whip open Explorer and see if it has trouble at the same time.

'Tis true.  I recall back in the 1.4 days (I think), I hacked JFileChooser code (perhaps FileSystemView) to return a hard-coded display name of "A:\" for a floppy drive (if on Windows) instead of letting Java do whatever native call to determine the drive name.  Terrible I know, but I recall back then there was some issue where Java would actually access the drive (you'd hear the physical drive access) before fetching the drive's name.  It just wasn't worth it back then, when Swing had so many other things going against it performance-wise.

I've also seen JFileChooser hang for long periods of time while trying to access information about certain mounted drives in both Linux and AIX.  Always in native calls, never in something you could control.
Offline BoBear2681

JGO Coder


Medals: 19



« Reply #31 - Posted 2014-10-15 23:01:38 »

mhm ... try invokeLater in actionPerformed anyway. just a guess Smiley


ActionListener.actionPerformed() is always called on the EDT.  All Swing event listeners are.  You only need to worry about SwingUtilities.invokeLater()/invokeAndWait() when you are off in your own thread, or something like the main application thread.

yes, but no.

if boot off things in the EDT right ahead it can still hang and screw you over. invokeLater from the EDT ensures the new action is queued to the end, rendering the current EDT process not block. Cranky

*edit*

I'm not quite sure I understand what you're saying here.  If a Swing EventListener class is not triggered on the EDT, you have found a bug in the JDK (or perhaps you have a custom JComponent going rogue and not playing by the rules).  I am assuming of course that the programmer is doing "the right thing," starts their Swing app on the EDT, etc.

If you're stating that running long-running processes in an ActionListener on the EDT causes the EDT to appear to hang, that is certainly true.  But if you're performing long-running tasks you should run them off the EDT in the first place, perhaps via SwingWorker.  Delaying a long-running task by calling SwingUtilities.invokeLater() when you're already on the EDT only delays when that long-running task will run on the EDT, it doesn't cause it not to occur.  The UI will still hang for the same length of time, only perhaps after performing a few other tasks.

Quote
on the other side, if you run invokeAndWait from the EDT you make it hang 100%.

Yes, again, I'm assuming the programmer isn't doing something stupid.
Offline KevinWorkman

« JGO Plugged Duke »


Medals: 283
Projects: 12
Exp: 12 years


HappyCoding.io - Coding Tutorials!


« Reply #32 - Posted 2014-10-16 13:16:22 »

if boot off things in the EDT right ahead it can still hang and screw you over. invokeLater from the EDT ensures the new action is queued to the end, rendering the current EDT process not block. Cranky

I'm not really sure what you're trying to say here, but if the EDT is already hung on a long-running process, using invokeLater() won't help you at all.

on the other side, if you run invokeAndWait from the EDT you make it hang 100%.

Erm, no. You'll get an error because you can't call invokeAndWait() from the EDT.

Lot of disinformation in this thread, which is why OP needs to post something that we can run instead of just throwing out random guesses.

HappyCoding.io - Coding Tutorials!
Happy Coding forum - Come say hello!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline basil_

« JGO Bitwise Duke »


Medals: 418
Exp: 13 years



« Reply #33 - Posted 2014-10-16 16:24:44 »

yes, you will get a Error for calling invokeAndWait from the EDT.

i was not clear enough i guess : "on the other side, if you could run invokeAndWait from the EDT you would make it hang 100%."

this is the opposite of "invokeLater from the EDT ensures the new action is queued to the end" - which can be very handy - if the current EDT code (not a long run process, nothing to do with SwingWorkers) - requires to finish (before new components are created or changed). that's too complicated.

things like https://github.com/Insubstantial can cause this.

usually you "should" not care about this things, yet you should always care about what is happening on which thread and what is allowed on which thread, especially with Swing.
Offline thedanisaur

JGO Knight


Medals: 59



« Reply #34 - Posted 2014-10-22 19:52:04 »

**sigh** It doesn't matter how small the program is, this always happens. I thought that it could be jogl, because I think it uses the awt eventqueue, but even when I copy and paste the tut programs off the internet this still happens.

Anyway since you guys want an MCVE here you go





1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
package FFS02_Leveled;
public class LevelEdMain
{
   static Thread thread;
   static LevelEd leveled;
   public static void main(String[] args)
   {      
      leveled = new LevelEd();
      thread = new Thread(leveled, "Main-Level Editor Thread");
      thread.start();
   }
}











1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
package FFS02_Leveled;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.awt.GLCanvas;
import javax.media.opengl.glu.GLU;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.filechooser.FileNameExtensionFilter;

public class LevelEd extends JFrame implements GLEventListener, KeyListener, MouseListener, MouseMotionListener, Runnable
{  
   private static final long serialVersionUID = 3669760361816887841L;
   
   //STANDARD VARIABLES
   private long                g_last_time;
   private GL2                g_gl;
   private GLU                g_glu;
   protected GLCanvas             g_glcanvas;
   
   
   public LevelEd()
   {
      super("FFS02Leveled");

      Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();//Get monitor dimensions
      float scale = 1.0f;//Set the scaling of the window
     
      //Set the window width and height
      int window_width = (int) (dimension.width * scale);
      int window_height = (int) (dimension.height * scale) - 48;
     
      init(window_width, window_height);//Initialize our variables
      startOpenGL();
   }
   
   public synchronized void display(GLAutoDrawable gld)
   {
      GL2 g_gl = gld.getGL().getGL2();
   }
   
   public void dispose(GLAutoDrawable arg0)
   {
   }
   
   public void init(GLAutoDrawable gld)
   {      
      //Make a new glu, glut, and gl for using OpenGL
      g_gl = gld.getGL().getGL2();
      g_glu = new GLU();

      g_gl.glClearColor(0.1f, 0.1f, 0.1f, 1.0f);//Set the default background color

      g_gl.glEnable(GL.GL_DEPTH_TEST);
      g_gl.glEnable(GL.GL_CULL_FACE);
      g_gl.glDepthFunc(GL.GL_LEQUAL);

       int sample_buffers[] = new int[1];
       int samples_for_buffer[] = new int[1];

       g_gl.glGetIntegerv(GL.GL_SAMPLE_BUFFERS, sample_buffers, 0);
       g_gl.glGetIntegerv(GL.GL_SAMPLES, samples_for_buffer, 0);
      g_gl.glEnable(GL.GL_MULTISAMPLE);

      g_gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
     
      g_gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
   }
   
   public void init(int window_width, int window_height)
   {
      int w = 80;
      int h = 24;
      JMenuBar menu_bar = new JMenuBar();
      setJMenuBar(menu_bar);

      JMenu menu_file = new JMenu("File");
      menu_file.setPreferredSize(new Dimension(50, h));
      menu_bar.add(menu_file);
     
      JMenuItem file_load = new JMenuItem("Load");
      file_load.setPreferredSize(new Dimension(w, h));
      file_load.addActionListener(new ActionListener()
      {
         public void actionPerformed(ActionEvent e)
         {  
            JFileChooser fc = new JFileChooser("./resources/levels");
            fc.setDialogTitle("Open .lvl File");
            fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Level File", "lvl");
            fc.setFileFilter(filter);
            int return_val = fc.showOpenDialog(null);
            if(return_val == JFileChooser.APPROVE_OPTION)
            {
               
            }
         }
      });
      menu_file.add(file_load);
   }
   public synchronized void keyPressed(KeyEvent e)
   {
   }
   public void keyReleased(KeyEvent e)
   {
   }
   public void keyTyped(KeyEvent e)
   {
   }
   public void mouseClicked(MouseEvent arg0)
   {
   }
   public void mouseDragged(MouseEvent arg0)
   {
   }
   public void mouseEntered(MouseEvent arg0)
   {
   }
   public void mouseExited(MouseEvent arg0)
   {
   }
   public void mouseMoved(MouseEvent arg0)
   {
   }
   public void mousePressed(MouseEvent arg0)
   {
   }
   public void mouseReleased(MouseEvent arg0)
   {
   }
   public void reshape(GLAutoDrawable gld, int x, int y, int width, int height)
   {
   }
   
   public void run()
   {
      boolean running = true;
      g_last_time = System.nanoTime();
      final double ns = 1_000_000_000.0 / 60.0;//Limits to 60 updates per second
      double delta = 0;

      double delta_time = 0;
      double limiter = 0.15;
      double previous_time = 1.0;
      double current_time = System.nanoTime() * 0.000000001;
     
      while(running)
      {
         long new_time = System.nanoTime();
         delta += (new_time - g_last_time) / ns;
         g_last_time = new_time;

         current_time = System.nanoTime() * 0.000000001;//Convert to Seconds
         delta_time = delta_time > limiter ? limiter : current_time - previous_time;
         previous_time = current_time;
         
         while(delta >= 1)
         {
            update(delta_time);
            delta--;
         }
         g_glcanvas.display();
      }
     
   }  
   
   private void startOpenGL()
   {
      g_glcanvas.addGLEventListener(this);
      g_glcanvas.addKeyListener(this);
      g_glcanvas.addMouseListener(this);
      g_glcanvas.addMouseMotionListener(this);
   }
   public synchronized void update(double delta_time)
   {
   }
   
}


Every village needs an idiot Cool
Offline joshi

Innocent Bystander





« Reply #35 - Posted 2018-04-12 07:17:30 »

Hi, am facing the same issue.could anyone answer the problem ? thanks.
Offline thedanisaur

JGO Knight


Medals: 59



« Reply #36 - Posted 2018-06-07 05:54:11 »

Since I happen to be on....I never found a solution to this problem. However, in my current project I don't have this issue. I could speculate reasons why was hanging then and it's not hanging now, but I think that would not be worth anyone's time at the moment (particularly mine, to go find that project and spin it up).

In the future please start a new thread and post specifics to your issue.

Every village needs an idiot Cool
Pages: 1 [2]
  ignore  |  Print  
 
 

 
EgonOlsen (348 views)
2018-06-10 19:43:48

EgonOlsen (342 views)
2018-06-10 19:43:44

EgonOlsen (290 views)
2018-06-10 19:43:20

DesertCoockie (514 views)
2018-05-13 18:23:11

nelsongames (803 views)
2018-04-24 18:15:36

nelsongames (790 views)
2018-04-24 18:14:32

ivj94 (1246 views)
2018-03-24 14:47:39

ivj94 (393 views)
2018-03-24 14:46:31

ivj94 (1057 views)
2018-03-24 14:43:53

Solater (412 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!