• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 05:40
CET 11:40
KST 19:40
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10
Community News
Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced15[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3RSL Season 3: RO16 results & RO8 bracket13
StarCraft 2
General
Chinese SC2 server to reopen; live all-star event in Hangzhou Maestros of the Game: Live Finals Preview (RO4) BGE Stara Zagora 2026 announced Weekly Cups (Nov 24-30): MaxPax, Clem, herO win SC2 Proleague Discontinued; SKT, KT, SGK, CJ disband
Tourneys
RSL Offline Finals Info - Dec 13 and 14! StarCraft Evolution League (SC Evo Biweekly) RSL Offline FInals Sea Duckling Open (Global, Bronze-Diamond) $5,000+ WardiTV 2025 Championship
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress Mutation # 500 Fright night Mutation # 499 Chilling Adaptation
Brood War
General
BW General Discussion Which season is the best in ASL? Data analysis on 70 million replays BGH Auto Balance -> http://bghmmr.eu/ [ASL20] Ask the mapmakers — Drop your questions
Tourneys
[BSL21] RO16 Group D - Sunday 21:00 CET [BSL21] RO16 Group A - Saturday 21:00 CET [Megathread] Daily Proleagues [BSL21] RO16 Group B - Sunday 21:00 CET
Strategy
Current Meta Game Theory for Starcraft How to stay on top of macro? PvZ map balance
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread ZeroSpace Megathread The Perfect Game Path of Exile
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Mafia Game Mode Feedback/Ideas TL Mafia Community Thread
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine The Big Programming Thread Artificial Intelligence Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Where to ask questions and add stream? The Automated Ban List
Blogs
Physical Exertion During Gam…
TrAiDoS
James Bond movies ranking - pa…
Topin
Thanks for the RSL
Hildegard
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1722 users

The Big Programming Thread - Page 548

Forum Index > General Forum
Post a Reply
Prev 1 546 547 548 549 550 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Manit0u
Profile Blog Joined August 2004
Poland17496 Posts
Last Edited: 2014-11-17 22:27:28
November 17 2014 22:24 GMT
#10941
On November 18 2014 00:09 BByte wrote:
Show nested quote +
On November 17 2014 21:25 goody153 wrote:
I was specifically tasked to convert 2 websites that was hardcoded into MVC coding style(or architecture or whatever the term i should use) so i did some googling and i ended up finding 3 PHP framework that apparently commonly used and i believe would help me on the task which are CakePHP, Laravel and CodeIgniter.

I won't ask which one is the best since they all probably have their own pros and cons. So my question would be which PHP framework between CakePHP, Laravel and CodeIgniter have you guys used or have been using ? or have you switched from one framework to another ? or which framework have you had a wonderful experience or have worked on you? which didn't ?


I haven't used any of the mentioned frameworks extensively, I use Symfony both at work and for some of my own projects. Based on what impressions I have of the three mentioned, I'd choose Laravel.

The best framework really depends on what you actually need to convert those sites. If they are rather simple, you may want to consider using a micro-framework. Even something simple will force you to use a proper MVC model and micro-frameworks can be a lot easier to learn. You certainly don't have to use or learn to use every component even if you pick a heavier option though.

When converting an existing site I'd especially consider support for different types of template and configuration files. If the sites are currently hardcoded, it's likely the view / template code is written in raw HTML + PHP. You may want to keep it that way and just separate the business logic. But if you also need to create some new templates a proper template engine can be useful. Mixing different types of templates may not be the cleanest solution, but in can mean a lot less work. Same goes for config files: Maybe you want to keep some of the old PHP or XML files, but want to use YAML for the new files. If the framework can seamlessly support different types of configuration, it's a little easier.


I'm also using Symfony (and now Kohana) and would also suggest Laravel. CodeIgniter is nice but it's rather dated and hasn't been developed for years so it might not adhere to the more modern approach and evolution of PHP itself. If you're new to the MVC pattern (that's what you call it) I'd suggest trying it out first in mini (formerly known simply as php-mvc) which is a micro-framework that let's you get the gist of it in 30 minutes or so. It's pretty bare bones but that's good, you'll learn how things work and it'll be much easier for you to jump to full-stack frameworks like Laravel or Symphony which offer a much higher level of abstraction. Because they offer all those abstraction layers you might find yourself doing stuff without actually knowing or fully understanding what's going on. I don't know about mini but php-mvc also had an "advanced" fork where you got SASS support and Twig templating engine.

I used to really hate Symfony, but after trying out some other frameworks I'm actually missing it in my new job (except for Sonata and CMF parts of it, I still despise them).
Time is precious. Waste it wisely.
Azerbaijan
Profile Blog Joined January 2010
United States660 Posts
November 17 2014 23:38 GMT
#10942
I can't get JSTL into my jsp. I am using this include statement which seems to work for everyone else on the internet.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

I am using maven and have the javaee-web-api dependency in my project and on my build path. I can see the JSTL packages inside the jar but my include statement just won't find them and I do not know why. It does work if I get the JSTL dependency specifically but that just makes wonder why they bundled the entire web api into one package if I can't actually use the stuff inside of it. I am sure I am missing something obvious ><
goody153
Profile Blog Joined April 2013
44236 Posts
November 18 2014 01:16 GMT
#10943
On November 18 2014 07:24 Manit0u wrote:
Show nested quote +
On November 18 2014 00:09 BByte wrote:
On November 17 2014 21:25 goody153 wrote:
I was specifically tasked to convert 2 websites that was hardcoded into MVC coding style(or architecture or whatever the term i should use) so i did some googling and i ended up finding 3 PHP framework that apparently commonly used and i believe would help me on the task which are CakePHP, Laravel and CodeIgniter.

I won't ask which one is the best since they all probably have their own pros and cons. So my question would be which PHP framework between CakePHP, Laravel and CodeIgniter have you guys used or have been using ? or have you switched from one framework to another ? or which framework have you had a wonderful experience or have worked on you? which didn't ?


I haven't used any of the mentioned frameworks extensively, I use Symfony both at work and for some of my own projects. Based on what impressions I have of the three mentioned, I'd choose Laravel.

The best framework really depends on what you actually need to convert those sites. If they are rather simple, you may want to consider using a micro-framework. Even something simple will force you to use a proper MVC model and micro-frameworks can be a lot easier to learn. You certainly don't have to use or learn to use every component even if you pick a heavier option though.

When converting an existing site I'd especially consider support for different types of template and configuration files. If the sites are currently hardcoded, it's likely the view / template code is written in raw HTML + PHP. You may want to keep it that way and just separate the business logic. But if you also need to create some new templates a proper template engine can be useful. Mixing different types of templates may not be the cleanest solution, but in can mean a lot less work. Same goes for config files: Maybe you want to keep some of the old PHP or XML files, but want to use YAML for the new files. If the framework can seamlessly support different types of configuration, it's a little easier.


I'm also using Symfony (and now Kohana) and would also suggest Laravel. CodeIgniter is nice but it's rather dated and hasn't been developed for years so it might not adhere to the more modern approach and evolution of PHP itself. If you're new to the MVC pattern (that's what you call it) I'd suggest trying it out first in mini (formerly known simply as php-mvc) which is a micro-framework that let's you get the gist of it in 30 minutes or so. It's pretty bare bones but that's good, you'll learn how things work and it'll be much easier for you to jump to full-stack frameworks like Laravel or Symphony which offer a much higher level of abstraction. Because they offer all those abstraction layers you might find yourself doing stuff without actually knowing or fully understanding what's going on. I don't know about mini but php-mvc also had an "advanced" fork where you got SASS support and Twig templating engine.

I used to really hate Symfony, but after trying out some other frameworks I'm actually missing it in my new job (except for Sonata and CMF parts of it, I still despise them).

Ok i'll try this php-mini first. Thanks .

On November 18 2014 00:09 BByte wrote:
Show nested quote +
On November 17 2014 21:25 goody153 wrote:
I was specifically tasked to convert 2 websites that was hardcoded into MVC coding style(or architecture or whatever the term i should use) so i did some googling and i ended up finding 3 PHP framework that apparently commonly used and i believe would help me on the task which are CakePHP, Laravel and CodeIgniter.

I won't ask which one is the best since they all probably have their own pros and cons. So my question would be which PHP framework between CakePHP, Laravel and CodeIgniter have you guys used or have been using ? or have you switched from one framework to another ? or which framework have you had a wonderful experience or have worked on you? which didn't ?


I haven't used any of the mentioned frameworks extensively, I use Symfony both at work and for some of my own projects. Based on what impressions I have of the three mentioned, I'd choose Laravel.

The best framework really depends on what you actually need to convert those sites. If they are rather simple, you may want to consider using a micro-framework. Even something simple will force you to use a proper MVC model and micro-frameworks can be a lot easier to learn. You certainly don't have to use or learn to use every component even if you pick a heavier option though.

When converting an existing site I'd especially consider support for different types of template and configuration files. If the sites are currently hardcoded, it's likely the view / template code is written in raw HTML + PHP. You may want to keep it that way and just separate the business logic. But if you also need to create some new templates a proper template engine can be useful. Mixing different types of templates may not be the cleanest solution, but in can mean a lot less work. Same goes for config files: Maybe you want to keep some of the old PHP or XML files, but want to use YAML for the new files. If the framework can seamlessly support different types of configuration, it's a little easier.


What i'm trying to convert is raw HTML + PHP coded and i would like to use majority of the codes from it since i don't want to recreate most of the functions.



Alright people has also been saying Symphony or Laravel so i'll try both and get the feel which i would like to use. And i won't be using codeigniter since people said that easier but there is no support behind it anymore.

Thank guys.
this is a quote
Manit0u
Profile Blog Joined August 2004
Poland17496 Posts
November 20 2014 02:12 GMT
#10944
Why are so many developers using MacBooks? Are they that good or is it just a trendy thing to do? I'm asking because I need a new laptop for work and am seriously considering giving it a shot even though I despise Apple products...
Time is precious. Waste it wisely.
ZenithM
Profile Joined February 2011
France15952 Posts
Last Edited: 2014-11-20 03:23:59
November 20 2014 02:28 GMT
#10945
My guess is that MacBooks are premium devices (good keyboard and touchpad, good screen, robust, good battery life etc..) and Mac OS X is POSIX compliant, which makes macbooks very usable in a Unix development setting. There are also a few productivity goodies on macbooks, like fancy multitouch touchpad gestures and such.

But they could probably do the same shit they do with a computer half as cheap. Apple's marketing and brand loyalty is just that good.
phar
Profile Joined August 2011
United States1080 Posts
November 20 2014 02:29 GMT
#10946
Solid product, and usually someone else (your company) is paying.
Who after all is today speaking about the destruction of the Armenians?
berated-
Profile Blog Joined February 2007
United States1134 Posts
November 20 2014 02:30 GMT
#10947
On November 18 2014 08:38 Azerbaijan wrote:
I can't get JSTL into my jsp. I am using this include statement which seems to work for everyone else on the internet.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

I am using maven and have the javaee-web-api dependency in my project and on my build path. I can see the JSTL packages inside the jar but my include statement just won't find them and I do not know why. It does work if I get the JSTL dependency specifically but that just makes wonder why they bundled the entire web api into one package if I can't actually use the stuff inside of it. I am sure I am missing something obvious ><


What container are you deploying to? How are you declaring your dependency for the javaee-web-api and what version?
Manit0u
Profile Blog Joined August 2004
Poland17496 Posts
November 20 2014 02:41 GMT
#10948
On November 20 2014 11:29 phar wrote:
Solid product, and usually someone else (your company) is paying.


The thing is, I have to buy it myself for my personal use. Just found out I can get just as good MSI laptop for half the price.
Time is precious. Waste it wisely.
WolfintheSheep
Profile Joined June 2011
Canada14127 Posts
November 20 2014 03:02 GMT
#10949
On November 20 2014 11:41 Manit0u wrote:
Show nested quote +
On November 20 2014 11:29 phar wrote:
Solid product, and usually someone else (your company) is paying.


The thing is, I have to buy it myself for my personal use. Just found out I can get just as good MSI laptop for half the price.

MSI and ASUS make good laptops for a good price, if you want something with a bit more power (especially graphics-wise).

There's a lot more options when it comes to extremely barebones machines.
Average means I'm better than half of you.
teamamerica
Profile Blog Joined July 2010
United States958 Posts
November 20 2014 07:40 GMT
#10950
Hey guys, I was wondering how the elasticsearch option "mlockall" to prevent JVM from using heap memory is actually implemented.

Also was wondering - at work they have some elasticsearch nodes (I don't work on them, I just do monitoring T_T) but I was looking into the boxes for some issue and was seeing few things I had question on

1) JVM were configured with mlockall but were still using swap (these are running on physical servers). Shouldn't they not be?
2) Servers have 100gb RAM and were at maybe 80gb usage, was seeing there was still some swap usage. Why would anything use swap space before ram gets filled (vm.swapiness set to 60 if thats reason)


RIP GOMTV. RIP PROLEAGUE.
Manit0u
Profile Blog Joined August 2004
Poland17496 Posts
November 20 2014 08:40 GMT
#10951
On November 20 2014 16:40 teamamerica wrote:
Hey guys, I was wondering how the elasticsearch option "mlockall" to prevent JVM from using heap memory is actually implemented.

Also was wondering - at work they have some elasticsearch nodes (I don't work on them, I just do monitoring T_T) but I was looking into the boxes for some issue and was seeing few things I had question on

1) JVM were configured with mlockall but were still using swap (these are running on physical servers). Shouldn't they not be?
2) Servers have 100gb RAM and were at maybe 80gb usage, was seeing there was still some swap usage. Why would anything use swap space before ram gets filled (vm.swapiness set to 60 if thats reason)




Ad. 2:

Swapping is necessary for two important reasons. First, when the system requires more memory than is physically available, the kernel swaps out less used pages and gives memory to the current application (process) that needs the memory immediately. Second, a significant number of the pages used by an application during its startup phase may only be used for initialization and then never used again. The system can swap out those pages and free the memory for other applications or even for the disk cache.

Source: http://www.linux.com/news/software/applications/8208-all-about-linux-swap-space
Time is precious. Waste it wisely.
Manit0u
Profile Blog Joined August 2004
Poland17496 Posts
November 20 2014 14:56 GMT
#10952


Good times...
Time is precious. Waste it wisely.
raNazUra
Profile Joined December 2012
United States10 Posts
November 20 2014 21:18 GMT
#10953
I have a code question. The long and the short of it is that I don't fully understand threads in Java, or perhaps simply their interaction with applets. Here's a simplified version of the problem I'm having:

+ Show Spoiler +
import java.applet.Applet;
import java.awt.Button;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TestApplet extends Applet {
public Button spawnThread;

private class ButtonPresser implements Runnable {

public Button endThread;
public TestApplet parent;
public Object notifier = new Object();

public ButtonPresser(TestApplet parent){
this.parent = parent;
}

@Override
public void run() {
synchronized(notifier){
endThread = new Button("End Thread");
endThread.setBounds(0,100,100,20);
endThread.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
synchronized(notifier) {
notifier.notify();
}
}
});
parent.add(endThread);

try {
notifier.wait();
System.out.println("Thread is done!");
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}

public void init() {
final TestApplet thisApp = this;
spawnThread = new Button("Spawn Thread");
spawnThread.setBounds(0,0,100,20);
spawnThread.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Thread t = new Thread(new ButtonPresser(thisApp));
t.run();
try {
t.join();
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
});
add(spawnThread);
}
}


What I am attempting to do is spawn a thread that adds a button to an applet that will kill said thread. In order to do this, I am creating a button whose listener tells it to notify the object on which the thread's run method is currently waiting, thereby allowing the run() to complete and the thread to terminate. However, when I run this and click on the Spawn Thread button, the End Thread button is added, and then the applet completely locks up (accepts no clicks and can't be closed, have to kill the process). Can anyone explain to me why this is? I'm sure I'm doing something fundamentally stupid but am not sure what it is.

Also, I know no one uses applets anymore, that's what I see on every Stack Overflow question I read, but my guess is that this problem is not inherent to applets, but rather to my understanding. Also it seems I should be trying to use the java.util.concurrent library, but I'd like to know why this doesn't work before moving there.
Speak the truth, even if your voice shakes
berated-
Profile Blog Joined February 2007
United States1134 Posts
November 21 2014 01:07 GMT
#10954
On November 21 2014 06:18 raNazUra wrote:
I have a code question. The long and the short of it is that I don't fully understand threads in Java, or perhaps simply their interaction with applets. Here's a simplified version of the problem I'm having:

+ Show Spoiler +
import java.applet.Applet;
import java.awt.Button;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TestApplet extends Applet {
public Button spawnThread;

private class ButtonPresser implements Runnable {

public Button endThread;
public TestApplet parent;
public Object notifier = new Object();

public ButtonPresser(TestApplet parent){
this.parent = parent;
}

@Override
public void run() {
synchronized(notifier){
endThread = new Button("End Thread");
endThread.setBounds(0,100,100,20);
endThread.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
synchronized(notifier) {
notifier.notify();
}
}
});
parent.add(endThread);

try {
notifier.wait();
System.out.println("Thread is done!");
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}

public void init() {
final TestApplet thisApp = this;
spawnThread = new Button("Spawn Thread");
spawnThread.setBounds(0,0,100,20);
spawnThread.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Thread t = new Thread(new ButtonPresser(thisApp));
t.run();
try {
t.join();
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
});
add(spawnThread);
}
}


What I am attempting to do is spawn a thread that adds a button to an applet that will kill said thread. In order to do this, I am creating a button whose listener tells it to notify the object on which the thread's run method is currently waiting, thereby allowing the run() to complete and the thread to terminate. However, when I run this and click on the Spawn Thread button, the End Thread button is added, and then the applet completely locks up (accepts no clicks and can't be closed, have to kill the process). Can anyone explain to me why this is? I'm sure I'm doing something fundamentally stupid but am not sure what it is.

Also, I know no one uses applets anymore, that's what I see on every Stack Overflow question I read, but my guess is that this problem is not inherent to applets, but rather to my understanding. Also it seems I should be trying to use the java.util.concurrent library, but I'd like to know why this doesn't work before moving there.


Thread.join

When you call thread.join() from the main thread, it is now going to wait on the other thread to finish before it moves on.

You've created a deadlock. Thread a creates thread b. Thread b must be stopped by an action on thread a. However, thread a is currently waiting for thread b to finish before it can respond. Everyone loses.

Also, you shouldn't be calling thread.run(). You should call thread.start().

Starting a thread
berated-
Profile Blog Joined February 2007
United States1134 Posts
November 21 2014 02:34 GMT
#10955
On November 20 2014 16:40 teamamerica wrote:
Hey guys, I was wondering how the elasticsearch option "mlockall" to prevent JVM from using heap memory is actually implemented.

Also was wondering - at work they have some elasticsearch nodes (I don't work on them, I just do monitoring T_T) but I was looking into the boxes for some issue and was seeing few things I had question on

1) JVM were configured with mlockall but were still using swap (these are running on physical servers). Shouldn't they not be?
2) Servers have 100gb RAM and were at maybe 80gb usage, was seeing there was still some swap usage. Why would anything use swap space before ram gets filled (vm.swapiness set to 60 if thats reason)




5 minutes of googling (so if its wrong, sorry..) shows that mlockall with the jvm is used through the lucid works java agent.

Lucid Works Java Agent

Are you guys following their recommended settings?
raNazUra
Profile Joined December 2012
United States10 Posts
November 21 2014 03:15 GMT
#10956
On November 21 2014 10:07 berated- wrote:
Show nested quote +
On November 21 2014 06:18 raNazUra wrote:
I have a code question. The long and the short of it is that I don't fully understand threads in Java, or perhaps simply their interaction with applets. Here's a simplified version of the problem I'm having:

+ Show Spoiler +
import java.applet.Applet;
import java.awt.Button;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TestApplet extends Applet {
public Button spawnThread;

private class ButtonPresser implements Runnable {

public Button endThread;
public TestApplet parent;
public Object notifier = new Object();

public ButtonPresser(TestApplet parent){
this.parent = parent;
}

@Override
public void run() {
synchronized(notifier){
endThread = new Button("End Thread");
endThread.setBounds(0,100,100,20);
endThread.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
synchronized(notifier) {
notifier.notify();
}
}
});
parent.add(endThread);

try {
notifier.wait();
System.out.println("Thread is done!");
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}

public void init() {
final TestApplet thisApp = this;
spawnThread = new Button("Spawn Thread");
spawnThread.setBounds(0,0,100,20);
spawnThread.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Thread t = new Thread(new ButtonPresser(thisApp));
t.run();
try {
t.join();
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
});
add(spawnThread);
}
}


What I am attempting to do is spawn a thread that adds a button to an applet that will kill said thread. In order to do this, I am creating a button whose listener tells it to notify the object on which the thread's run method is currently waiting, thereby allowing the run() to complete and the thread to terminate. However, when I run this and click on the Spawn Thread button, the End Thread button is added, and then the applet completely locks up (accepts no clicks and can't be closed, have to kill the process). Can anyone explain to me why this is? I'm sure I'm doing something fundamentally stupid but am not sure what it is.

Also, I know no one uses applets anymore, that's what I see on every Stack Overflow question I read, but my guess is that this problem is not inherent to applets, but rather to my understanding. Also it seems I should be trying to use the java.util.concurrent library, but I'd like to know why this doesn't work before moving there.


Thread.join

When you call thread.join() from the main thread, it is now going to wait on the other thread to finish before it moves on.

You've created a deadlock. Thread a creates thread b. Thread b must be stopped by an action on thread a. However, thread a is currently waiting for thread b to finish before it can respond. Everyone loses.

Also, you shouldn't be calling thread.run(). You should call thread.start().

Starting a thread


Yes, the join() functionality is what I wanted, but I think I know where the problem is now. I had been forgetting to think about which thread deals with the actual ClickEvent, which presumably would be the main thread for applets. So then the main thread is waiting on the created thread to finish and can't jump out to execute ActionListener code for button presses? Time to go test this.
Speak the truth, even if your voice shakes
berated-
Profile Blog Joined February 2007
United States1134 Posts
November 21 2014 03:27 GMT
#10957
On November 21 2014 12:15 raNazUra wrote:
Show nested quote +
On November 21 2014 10:07 berated- wrote:
On November 21 2014 06:18 raNazUra wrote:
I have a code question. The long and the short of it is that I don't fully understand threads in Java, or perhaps simply their interaction with applets. Here's a simplified version of the problem I'm having:

+ Show Spoiler +
import java.applet.Applet;
import java.awt.Button;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TestApplet extends Applet {
public Button spawnThread;

private class ButtonPresser implements Runnable {

public Button endThread;
public TestApplet parent;
public Object notifier = new Object();

public ButtonPresser(TestApplet parent){
this.parent = parent;
}

@Override
public void run() {
synchronized(notifier){
endThread = new Button("End Thread");
endThread.setBounds(0,100,100,20);
endThread.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
synchronized(notifier) {
notifier.notify();
}
}
});
parent.add(endThread);

try {
notifier.wait();
System.out.println("Thread is done!");
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}

public void init() {
final TestApplet thisApp = this;
spawnThread = new Button("Spawn Thread");
spawnThread.setBounds(0,0,100,20);
spawnThread.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Thread t = new Thread(new ButtonPresser(thisApp));
t.run();
try {
t.join();
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
});
add(spawnThread);
}
}


What I am attempting to do is spawn a thread that adds a button to an applet that will kill said thread. In order to do this, I am creating a button whose listener tells it to notify the object on which the thread's run method is currently waiting, thereby allowing the run() to complete and the thread to terminate. However, when I run this and click on the Spawn Thread button, the End Thread button is added, and then the applet completely locks up (accepts no clicks and can't be closed, have to kill the process). Can anyone explain to me why this is? I'm sure I'm doing something fundamentally stupid but am not sure what it is.

Also, I know no one uses applets anymore, that's what I see on every Stack Overflow question I read, but my guess is that this problem is not inherent to applets, but rather to my understanding. Also it seems I should be trying to use the java.util.concurrent library, but I'd like to know why this doesn't work before moving there.


Thread.join

When you call thread.join() from the main thread, it is now going to wait on the other thread to finish before it moves on.

You've created a deadlock. Thread a creates thread b. Thread b must be stopped by an action on thread a. However, thread a is currently waiting for thread b to finish before it can respond. Everyone loses.

Also, you shouldn't be calling thread.run(). You should call thread.start().

Starting a thread


Yes, the join() functionality is what I wanted, but I think I know where the problem is now. I had been forgetting to think about which thread deals with the actual ClickEvent, which presumably would be the main thread for applets. So then the main thread is waiting on the created thread to finish and can't jump out to execute ActionListener code for button presses? Time to go test this.


Why do you want join? You shouldn't care on the thread that creates the second thread what the second thread is doing? You just want it running, yes? Join explicitly takes away the whole value that you created by offloading to another thread by rejoining them together.
phar
Profile Joined August 2011
United States1080 Posts
November 21 2014 05:34 GMT
#10958
On November 20 2014 11:41 Manit0u wrote:
Show nested quote +
On November 20 2014 11:29 phar wrote:
Solid product, and usually someone else (your company) is paying.


The thing is, I have to buy it myself for my personal use. Just found out I can get just as good MSI laptop for half the price.

Yea I personally wouldn't spend the markup out of my own pocket. But then again, if I had no company phone and had to get my own phone, I'd be eyeing the $100 moto e.
Who after all is today speaking about the destruction of the Armenians?
raNazUra
Profile Joined December 2012
United States10 Posts
November 21 2014 06:03 GMT
#10959
On November 21 2014 12:27 berated- wrote:
Show nested quote +
On November 21 2014 12:15 raNazUra wrote:
On November 21 2014 10:07 berated- wrote:
On November 21 2014 06:18 raNazUra wrote:
I have a code question. The long and the short of it is that I don't fully understand threads in Java, or perhaps simply their interaction with applets. Here's a simplified version of the problem I'm having:

+ Show Spoiler +
import java.applet.Applet;
import java.awt.Button;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TestApplet extends Applet {
public Button spawnThread;

private class ButtonPresser implements Runnable {

public Button endThread;
public TestApplet parent;
public Object notifier = new Object();

public ButtonPresser(TestApplet parent){
this.parent = parent;
}

@Override
public void run() {
synchronized(notifier){
endThread = new Button("End Thread");
endThread.setBounds(0,100,100,20);
endThread.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
synchronized(notifier) {
notifier.notify();
}
}
});
parent.add(endThread);

try {
notifier.wait();
System.out.println("Thread is done!");
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}

public void init() {
final TestApplet thisApp = this;
spawnThread = new Button("Spawn Thread");
spawnThread.setBounds(0,0,100,20);
spawnThread.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Thread t = new Thread(new ButtonPresser(thisApp));
t.run();
try {
t.join();
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
});
add(spawnThread);
}
}


What I am attempting to do is spawn a thread that adds a button to an applet that will kill said thread. In order to do this, I am creating a button whose listener tells it to notify the object on which the thread's run method is currently waiting, thereby allowing the run() to complete and the thread to terminate. However, when I run this and click on the Spawn Thread button, the End Thread button is added, and then the applet completely locks up (accepts no clicks and can't be closed, have to kill the process). Can anyone explain to me why this is? I'm sure I'm doing something fundamentally stupid but am not sure what it is.

Also, I know no one uses applets anymore, that's what I see on every Stack Overflow question I read, but my guess is that this problem is not inherent to applets, but rather to my understanding. Also it seems I should be trying to use the java.util.concurrent library, but I'd like to know why this doesn't work before moving there.


Thread.join

When you call thread.join() from the main thread, it is now going to wait on the other thread to finish before it moves on.

You've created a deadlock. Thread a creates thread b. Thread b must be stopped by an action on thread a. However, thread a is currently waiting for thread b to finish before it can respond. Everyone loses.

Also, you shouldn't be calling thread.run(). You should call thread.start().

Starting a thread


Yes, the join() functionality is what I wanted, but I think I know where the problem is now. I had been forgetting to think about which thread deals with the actual ClickEvent, which presumably would be the main thread for applets. So then the main thread is waiting on the created thread to finish and can't jump out to execute ActionListener code for button presses? Time to go test this.


Why do you want join? You shouldn't care on the thread that creates the second thread what the second thread is doing? You just want it running, yes? Join explicitly takes away the whole value that you created by offloading to another thread by rejoining them together.


Ok, so I'll just give a high-level picture of what I was hoping for. There's probably a proper paradigm for doing what I want to do, so that would also be welcome advice. Here's what I want:

main:
Run some code
Create a couple buttons, one of which is "Done tinkering"
Run some more code based on previous button presses (including possible branches)
More buttons, including "Done" button,
etc.

So my goal was to spawn a new thread for all the buttons, which will terminate when I'm done messing with them, at which point the main thread continues on. Originally I was being even terribler, and passing the future code to be executed around inside Buttons, which would get sent an event when the "Done" button was pressed.

Basically, when "Done" is pressed, I would greatly prefer to back out one level to whatever set it up, rather than pass the future code into the "Done" creation to be executed on the press.
Speak the truth, even if your voice shakes
berated-
Profile Blog Joined February 2007
United States1134 Posts
November 21 2014 10:49 GMT
#10960
On November 21 2014 15:03 raNazUra wrote:
Show nested quote +
On November 21 2014 12:27 berated- wrote:
On November 21 2014 12:15 raNazUra wrote:
On November 21 2014 10:07 berated- wrote:
On November 21 2014 06:18 raNazUra wrote:
I have a code question. The long and the short of it is that I don't fully understand threads in Java, or perhaps simply their interaction with applets. Here's a simplified version of the problem I'm having:

+ Show Spoiler +
import java.applet.Applet;
import java.awt.Button;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TestApplet extends Applet {
public Button spawnThread;

private class ButtonPresser implements Runnable {

public Button endThread;
public TestApplet parent;
public Object notifier = new Object();

public ButtonPresser(TestApplet parent){
this.parent = parent;
}

@Override
public void run() {
synchronized(notifier){
endThread = new Button("End Thread");
endThread.setBounds(0,100,100,20);
endThread.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
synchronized(notifier) {
notifier.notify();
}
}
});
parent.add(endThread);

try {
notifier.wait();
System.out.println("Thread is done!");
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}

public void init() {
final TestApplet thisApp = this;
spawnThread = new Button("Spawn Thread");
spawnThread.setBounds(0,0,100,20);
spawnThread.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Thread t = new Thread(new ButtonPresser(thisApp));
t.run();
try {
t.join();
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
});
add(spawnThread);
}
}


What I am attempting to do is spawn a thread that adds a button to an applet that will kill said thread. In order to do this, I am creating a button whose listener tells it to notify the object on which the thread's run method is currently waiting, thereby allowing the run() to complete and the thread to terminate. However, when I run this and click on the Spawn Thread button, the End Thread button is added, and then the applet completely locks up (accepts no clicks and can't be closed, have to kill the process). Can anyone explain to me why this is? I'm sure I'm doing something fundamentally stupid but am not sure what it is.

Also, I know no one uses applets anymore, that's what I see on every Stack Overflow question I read, but my guess is that this problem is not inherent to applets, but rather to my understanding. Also it seems I should be trying to use the java.util.concurrent library, but I'd like to know why this doesn't work before moving there.


Thread.join

When you call thread.join() from the main thread, it is now going to wait on the other thread to finish before it moves on.

You've created a deadlock. Thread a creates thread b. Thread b must be stopped by an action on thread a. However, thread a is currently waiting for thread b to finish before it can respond. Everyone loses.

Also, you shouldn't be calling thread.run(). You should call thread.start().

Starting a thread


Yes, the join() functionality is what I wanted, but I think I know where the problem is now. I had been forgetting to think about which thread deals with the actual ClickEvent, which presumably would be the main thread for applets. So then the main thread is waiting on the created thread to finish and can't jump out to execute ActionListener code for button presses? Time to go test this.


Why do you want join? You shouldn't care on the thread that creates the second thread what the second thread is doing? You just want it running, yes? Join explicitly takes away the whole value that you created by offloading to another thread by rejoining them together.


Ok, so I'll just give a high-level picture of what I was hoping for. There's probably a proper paradigm for doing what I want to do, so that would also be welcome advice. Here's what I want:

main:
Run some code
Create a couple buttons, one of which is "Done tinkering"
Run some more code based on previous button presses (including possible branches)
More buttons, including "Done" button,
etc.

So my goal was to spawn a new thread for all the buttons, which will terminate when I'm done messing with them, at which point the main thread continues on. Originally I was being even terribler, and passing the future code to be executed around inside Buttons, which would get sent an event when the "Done" button was pressed.

Basically, when "Done" is pressed, I would greatly prefer to back out one level to whatever set it up, rather than pass the future code into the "Done" creation to be executed on the press.


Thanks for the explanation and high level view, it makes things easier than just looking at a block of code. I'm by no means an applet expert, but, I'm going to try to restate what I believe you are trying to accomplish and the describe the approach I would take.

You want to create an applet with action buttons on it, we'll call them A, B, and C for short. When you click any of the buttons, you will add a Stop (A|B|C) button, as well as start the Action (A|B|C). Clicking the stop button will terminate the action.

If this is the case, I would have some sort of listener on buttons A, B, C like you do now. However, from looking at your code, I would change where the logic runs. For me, it makes most sense for the original button listener to
- create the thread
- create the stop button
- create the stop button listener with a reference to the created thread
- start the thread
- add the button to the screen

Since the newly created button listener has reference to the newly created thread, the only thing you'll have to do click is to stop the thread. No reason for joins anywhere. The reason I would do it like this is from a separation of concerns part. The thread should be responsible for doing whatever background logic you want to be happening is. The main applet and button listeners are responsible for the coordination of the creation of threads and buttons.
Prev 1 546 547 548 549 550 1032 Next
Please log in or register to reply.
Live Events Refresh
The PondCast
10:00
Episode 74
CranKy Ducklings36
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
SortOf 167
ProTech93
StarCraft: Brood War
Britney 24578
GuemChi 1399
Horang2 1270
Calm 1234
actioN 555
Jaedong 466
BeSt 391
Mini 307
firebathero 284
EffOrt 230
[ Show more ]
Hyuk 219
Dewaltoss 136
Last 117
Snow 106
Light 104
Hyun 99
Larva 93
Pusan 90
Sharp 87
Rush 70
hero 70
Killer 66
Barracks 55
ggaemo 47
Sacsri 44
sorry 41
ZerO 37
Shine 35
ToSsGirL 29
Shinee 20
Bale 19
soO 18
Noble 13
Backho 12
NaDa 9
Mong 8
Hm[arnc] 6
Dota 2
NeuroSwarm89
XcaliburYe26
League of Legends
JimRising 400
C9.Mang0267
Reynor74
Counter-Strike
olofmeister1769
shoxiejesuss659
Super Smash Bros
Westballz11
Other Games
summit1g12498
ceh9653
WinterStarcraft577
crisheroes415
KnowMe52
Mew2King45
ZerO(Twitch)5
Organizations
StarCraft: Brood War
Kim Chul Min (afreeca) 794
Other Games
gamesdonequick499
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• LUISG 29
• StrangeGG 23
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• lizZardDota257
League of Legends
• Jankos1979
Upcoming Events
OSC
5h 20m
Demi vs Mixu
Nicoract vs TBD
Babymarine vs MindelVK
ForJumy vs TBD
Shameless vs Percival
Replay Cast
13h 20m
Korean StarCraft League
1d 16h
CranKy Ducklings
1d 23h
WardiTV 2025
2 days
SC Evo League
2 days
BSL 21
2 days
Sziky vs OyAji
Gypsy vs eOnzErG
OSC
2 days
Solar vs Creator
ByuN vs Gerald
Percival vs Babymarine
Moja vs Krystianer
EnDerr vs ForJumy
sebesdes vs Nicoract
Sparkling Tuna Cup
2 days
WardiTV 2025
3 days
[ Show More ]
OSC
3 days
BSL 21
3 days
Bonyth vs StRyKeR
Tarson vs Dandy
Replay Cast
3 days
Wardi Open
4 days
StarCraft2.fi
4 days
Monday Night Weeklies
4 days
Replay Cast
4 days
WardiTV 2025
5 days
StarCraft2.fi
5 days
PiGosaur Monday
5 days
StarCraft2.fi
6 days
Tenacious Turtle Tussle
6 days
The PondCast
6 days
Liquipedia Results

Completed

Proleague 2025-11-30
RSL Revival: Season 3
Light HT

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
CSCL: Masked Kings S3
Slon Tour Season 2
Acropolis #4 - TS3
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
Kuram Kup
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.