wtf are u calling this in a loop for.
and this:Code:new URL("http://website.com/vps/reset.php?pass=jilixpie").openStream().close()
Just give up.Code:System.gc();
Anyway its too many requests and your calling system.gc in a while loop....
|
This is consuming A LOT of CPU. According to the tutorial this is to be placed in Server class, with an initialization (WebCommThread.run()) in the main-method. I'm not too experienced with Threads, but could Thread.sleep(int miliseconds) be used here? if so, how?
Here's the full tutorial; Players online without MySQLCode:public static Thread WebCommThread = new Thread ( new Runnable(){ long lastUpdate = 0; @Override public void run(){ while(true){ try{ if(System.currentTimeMillis() - lastUpdate > 1000 * 60 * 5 || Server.forceWebUpdate){ lastUpdate = System.currentTimeMillis(); new URL("http://website.com/vps/reset.php?pass=jilixpie").openStream().close(); for(Player p1: PlayerHandler.players){ if(p1 != null){ Client p = (Client)p1; if(!p.properLogout) new URL("http://website.com/vps/add.php?pass=jilixpie&u=" + p.playerName.replaceAll(" ","%20")).openStream().close(); } } if(Server.forceWebUpdate) Server.forceWebUpdate = false; System.gc(); } }catch(Exception e){} } } } );
wtf are u calling this in a loop for.
and this:Code:new URL("http://website.com/vps/reset.php?pass=jilixpie").openStream().close()
Just give up.Code:System.gc();
Anyway its too many requests and your calling system.gc in a while loop....
I'm so glad only 90% of people in here are like you, acting like you know it all and everyone else knows shit. Why just posting for the post count btw?
"Anyway" I guess by "just give up" you are implying that I made this, even though I clearly stated the followed a tutorial and that I was seeking advice to improve this piece of code, seeing as I already knew it impacted performance greatly.
Anyway, thanks for the insignificant help you could provide me with, I guess this isn't the task for you then.
Stop checking when u last updated and sleep.
I have already tried this:
This I can tell is half-assed by the looks of it but I just wanted to see if it would better the situation, which it did. The CPU usage is now at 100%...Code:public static Thread WebCommThread = new Thread ( new Runnable(){ long lastUpdate = 0; @Override public void run(){ while(true){ try{ if(System.currentTimeMillis() - lastUpdate > 1000 * 60 * 5 || Server.forceWebUpdate){ lastUpdate = System.currentTimeMillis(); new URL("http://website.com/vps/reset.php?pass=jilixpie").openStream().close(); for(Player p1: PlayerHandler.players){ if(p1 != null){ Client p = (Client)p1; if(!p.properLogout) new URL("http://website.com/vps/add.php?pass=jilixpie&u=" + p.playerName.replaceAll(" ","%20")).openStream().close(); } } if(Server.forceWebUpdate) Server.forceWebUpdate = false; System.gc(); Thread.sleep(60000); } }catch(Exception e){} } } } );
So how would you do it?
If you don't need it to update has much put in sleep that might help, sorry for late post didn't refresh.
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |
Tags for this Thread |