Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!

Billy Bob

+ Follow
since Feb 05, 2004
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Billy Bob

Hopefully this is the right forum, I didn't know whether or not in belonged in sockets or threads, so the mods can move it to the other one if necessary, and sorry for the problems if you do.

So, what we're suppose to be doing is creating a multi-threaded server that allows for, possibly, an infinite amount of clients. The program keeps running till one of the clients sends the "kill" command to the server, which keeps running and accepting clients until there are no more connected. Everything works, EXCEPT the stuff to kill the server. Here's what I got also contains the SocketHandler class):
it begins by making a new ServerSocket, followed by an instance over my server class, and a Socket s. It then goes into a while loop that looks like:

works fine. the SocketHandler class works fine too, it can do everything it's suppose to and detect the kill command. Now from the requiriments I have this is how it says to do this. When kill is called, set done = true, call server.theThread.interrupt() to interrupt accept, and in the exception handler do some stuff. The problem is, when I call server.theThread.interrupt, it's not doing anything. I understand why it needs to be called, but it really makes no sense why it should be called the way it is, and it's also not working. Any suggestions would be appreciated.
If you go to, click on Tutorials, there is a tic-tac-toe tutorial on there. It's written in C for the GBA, but the win function is nothing but an if statement. Not very elegant, but it does get the job done, hope it helps.
15 years ago

other than some print statements and declaring ints for the command line args, that's it for master. However, I"m not allowed to change any of this code. And, Bag is declaring Stack a.
[ October 10, 2004: Message edited by: Billy Boob ]
This is giving me a headache. I changed the way I was doing things. I noticed in the Master class that they were importing java.util.Stack and it wasn't being used, so I decided to use it. Now my bag class does this:

and I changed my worker class to do the following

I really thought this would work, but now running the same tests cases as earlier, it works about 66% of the time now. It doesn't block as much as it did before, so it has to be getting stuck in the get() method, since put() now just adds it to a stack.
haha it's so funny, returns 90 results for it, but im thinking most people, like me, don't have a name like this listed lol.
15 years ago
Not to sound bad, but how do you know it's not my real name? It really is, but if you want I can change it to something different.
15 years ago
I'm getting my B.S. in Computer Science, graduating next year, and had a few questions. I've taken tons of classes in Java, since all of them use it basically, ranging from the basic stuff to data structures. I wouldn't call myself and expert, but I fairly good with Java. Here's where I get to my question. I've been looking at job positions, and that call for Java experience and usually say something about J2EE, JSP, or a bunch of other acronyms. All I've ever had to use for school is J2SE, and for along time I was just using Notepad, but for the past year or so I've been using the wonder that is Eclipse . Basically, my question is this, where should I go next? All those acronmys I mentioned earlier, which are the most important to know when looking for a job? Is just knowing how to do programming in Java good enough? I'd like this to be a Java topic, not learn C++ or something, cause I already have experience with C/C++, PHP, VB, and more. Thanks in advance, and I hope this was the right board to post this in.
[ October 09, 2004: Message edited by: Billy Boob ]
15 years ago
^ I sent you a PM. I posted the code to the worker class earlier, it was:

that's it, all there is in there. Which is why I'm thinking it's not right. The code for the master class was supplied for us, and we're not allowed to change it. It creates an array of threads, creates the threads in a for loop and starts them in there too, then right after that it does a for loop using a command line argument to put Tasks into the task bag(tasks.put(Task(yadda yadda yadda))). Then it does another for loop, that does the same number of iterations as the one above, but instead gets Answers out of the result bag(ans = (Answer)results.get();. Then it calls tasks.done() (which is located in the Bag class, and I have no code for as of now). That's all it does, there are a few System.out.prints to show what is happening, but nothign else.
[ October 09, 2004: Message edited by: Billy Boob ]
I didn't say anything about not being able to call it.... I said I don't know what it's suppose to do, therefor I can not write it. I have to do everything but program Master, which I have, and sometimes it works, sometimes it kinda works, sometimes it doesn't work at all, as I stated above. Honestly, it's not that confusing, i just can't figure out why it freezes sometimes but still manages to get the correct answer, and sometimes it will even go as far as printing it out.
Only the get and put methods can manipulate them. And as stated somewhere above, I have no idea waht done is suppose to do, and has 0 lines of code for it. I thought it was just something general, for all I know it's just suppose to printout something, but I honestlty have no idea.
1. "The master thread creates the threads, puts the tasks into worker objects, and then starts the Worker(worker.start()). The Master then puts the task into the task bag, and then it gets the results from the result bag." -- I assume "puts the tasks into worker objects" should be "gives the task and result bags to the worker objects", correct? Master creates the threads and starts them, then puts Tasks into the Bag called task.

Does each worker get its own pair of bags? Each worker gets a reference to the 2 bags created in the master thread.

Is Bag truly intended to hold only one item at a time?
Yeah, I believe it is. I have 2 bags, and each one can hold one element.

Does Master put many Tasks into each task Bag or just one?
Master puts many Tasks into 1 Bag! There are only ever 2 bags, called task and result, and these are created in Master.

If only one Task is put into each task bag, does Master put it into the bag before or after starting each Worker? It starts the threads, then puts the tasks into the task bag.

How do the worker threads know that there are no more tasks to be had from their bags? I suspect this is the point of the done() method. Your guess is as good as mine.

Sorry about all this confusion, the specifications for this suck, and I can't contact anyone cause they're all on break. Not to mention, I have limited knowledge of threads since people don't like to teach them.
Hrmmmm.... I'll try to explain better this time. First off, here is an overview of all my classes:

Master - can't change the code here, but it puts things into a task bag, and gets things out of a result bag, so there are two seperate objects(task and result) of the same type.

Worker - This takes the two Bags as parameters, plus an int as a reference for which thread it is. So I have two bags called task and result. It also contains the run method I put up above.

Task - Takes in some parameters and does the operations on them, just has a constructor and works perfectly well.

Answer - Just like the Task, just stores some information, works fine.

Bag - 2 parameters, boolean variable called available and the Object to store. Has the get and put methods mentioned above, plus the done() method is suppose to be here but I have no idea what it's suppose to do, and not really worried with it at this moment.

The master thread creates the threads, puts the tasks into worker objects, and then starts the Worker(worker.start()). The Master then puts the task into the task bag, and then it gets the results from the result bag.

The run() method in the worker class is supposed to be doing the following: it goes into the task bag and gets the value stored in the object in the bag(which is of type Task). It then creates an Answer object, and stores the value into that object. Then it's supposed to put the Answer object into a results bag(different than the task bag). So I have 2 bags, result and task. I hope this makes alot more sense. I posted all the code above that really mattered, since 2 classes are nothign but containers, and I can't change one.
[ October 08, 2004: Message edited by: Billy Boob ]
I'm working on this program, and I have no idea why I'm getting this output. It's like, 33% of the time it works flawlessly, 33% it works somewhat, and the other 33% it doesn't work at all. Here's what's going on, it's a producer/consumer type thing(bag of tasks pardigm to be exact). So my Master thread is making tasks, and putting them into a Bag, just like it's suppose too. I'm putting generic Object tasks into the bag, and the Bag class has get(), put(), and done(). Get and put's code is:

very standard. I have a Task class, which just takes in data, and performs the necessary operations on them. Here's where I think the problem is. My worker class, the one that extends thread and has the run() method in it, isin't doing what it's suppose to, I don't think. Here's the run() method:

It's suppose to get a double from inside the Task currently in the task Bag, create an Answer object, and put that object into the results Bag. The output I'm getting depends on the parameters(all ints) that I give the program. It will either caclulate and print the correct answer and then end properly, calculate and print the right answer and freeze, or not print the answer and freeze. Very confused, and any help is appreciated. I also am not too sure what the done() method is suppose to be doing, just part of the requirments.....
[ October 08, 2004: Message edited by: Billy Boob ]
I don't know if anybody here can help but this problem is making me go insane. Here's what I have to do:
Write a recursive program that finds ALL LEGAL PATHS whose cost is <= to X(command line argument). Read from a file, output good points of the maze into a file, etc. Here is a sample maze file
3 3 <~~~~ 3 x 3 maze
0 1 1
0 0 0
1 0 0
0's are paths, 1's are walls. As you can see that maze has 2 correct paths. I can get my program to find one good path, but not all paths. I also can't figure out how to tell if it hits a wall or the edge of the maze. Any help would be appreciated, once I'm done with this I have to do an iterative maze solver, doesn't that sound like fun too?
16 years ago