Need help in threading implementation of my locking mechanism code

Graphical implementation of the test and set locking

Page 1 of 1

3 Replies - 758 Views - Last Post: 19 February 2009 - 09:19 AM Rate Topic: -----

#1 airamana  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 16-February 09

Need help in threading implementation of my locking mechanism code

Posted 16 February 2009 - 07:09 AM

I'm still new in JAVA because I've always coded programs using C and I thought of taking steps to learn this language..hope you could increase my knowledge of this language..

The problem is that I can't get the threading implementation right in my test and set code. What my program does are the following:
1.) Ask user for number of jobs
2.)Ask user for the type of locking mechanism(e.g Test and Set, Sempahore,wait and signal)
3.)Then after the user chooses it would open a gui where the graphical representation of the type of locking mechanism will be seen. In this part there will be a critical region (mine is a rectangle) that would represent when a job enters it..And when a job enters it the rectangle will fill up or be shaded up..Then this will repeat until the number of jobs are completed. Job size may not be required.
4.) Then after everything is done then it will loop back to number 1.


So 1,2, and 4 works but in 3 i'm really having a hard time implementing it because of the threading part..So if you can give me ideas perhaps you can help me in solving this problem...These are just two of the many files i have in my project..


import javax.swing.*;
import java.awt.*;




public class CriticalRegion extends JPanel {
		int height,partition;

		/**public void output (int height, int partition) {

			this.height = height;
			this.partition = partition;
			System.out.println("block" + partition);


		}**/

		public void paint(Graphics g) {


			g.setColor(Color.RED);

		if(height != 300 )
		{

				g.drawRect(10, 10, 250, 300);
				//g.drawRect(0,0,150,200);

				g.fillRect(10, 10, 250, 300);
				System.out.println("block 0");
				setVisible(true);
				System.out.println("block 0");

		}

		else{
			g.drawRect(10, 10, 250, 300);
			g.fillRect(10, 10, 250, 300);
			setVisible(true);
			

		}

	 }

}
class Label extends JPanel {
	public void paint(Graphics g)
	{
		g.setColor(Color.white);
		g.drawString("Critical Region", 0, 5);
		setVisible(true);

	}
}



import java.util.Timer;
import java.util.TimerTask;

public class TestandSet{
		int count=0,counter=0;
		int cJobSize;
		int cJobNumber;
		GetJob currentJob;
		long delay;

		 Timer t1 = new Timer();
		 //Timer t2 = new Timer();
		 //Timer t3 = new Timer();
		 //Timer t4 = new Timer();
		 //Timer t5 = new Timer();

		 TimerTask task1 = new T1();


	public void TestandSet(GetJob Job) {
		this.currentJob = Job;
		cJobSize = currentJob.getSize();
		cJobNumber = currentJob.getNumber();
		count=0;

		do{
	  

					/**Global.free[count]=false;
					Global.JobSize[count] = cJobSize;
					Global.JobNumber[count] = cJobNumber;
					delay = cJobSize * 1000;
					**/
					Global.JobSize[0] = cJobSize;
						cJobSize = cJobSize /2;
						Global.rect.setBounds(70, 15, 150, 61);
						//Global.rect.output(cJobSize, count);
						System.out.println("Job " + cJobNumber + " Put in: " + count);
						 t1.schedule(task1, delay);
			Global.WaitList.enqueue(currentJob);
			Global.list.addElement("Job" + counter + " = " + cJobSize + "Kb" + "Status: = 1");
					counter++;
			   


		}while(counter < Global.jobnumber);
/**
		while(counter != count)
		{
			Global.WaitList.enqueue(currentJob);
			Global.list.addElement("Job" + cJobNumber + " = " + cJobSize + "Kb" + "Status: = 1");
			counter++;
		}
**/
	}


}


This post has been edited by airamana: 16 February 2009 - 08:28 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Need help in threading implementation of my locking mechanism code

#2 ayman_mastermind  Icon User is offline

  • human.setType("geek");
  • member icon

Reputation: 126
  • View blog
  • Posts: 1,860
  • Joined: 12-December 08

Re: Need help in threading implementation of my locking mechanism code

Posted 16 February 2009 - 07:17 AM

Please write your question in the post and not in the post description, in addition please elaborate more about your problem and tell us what kind of help you need in your graphical implementation in the test and set locking... Thanks
Was This Post Helpful? 1
  • +
  • -

#3 airamana  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 16-February 09

Re: Need help in threading implementation of my locking mechanism code

Posted 16 February 2009 - 08:02 AM

View Postayman_mastermind, on 16 Feb, 2009 - 06:17 AM, said:

Please write your question in the post and not in the post description, in addition please elaborate more about your problem and tell us what kind of help you need in your graphical implementation in the test and set locking... Thanks


Thanks for the info..i'm still new to this site..SO I have edited my post and placed my problem..Hope you could give some advice..
Was This Post Helpful? 0
  • +
  • -

#4 airamana  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 16-February 09

Re: Need help in threading implementation of my locking mechanism code

Posted 19 February 2009 - 09:19 AM

So I already solved my project..thanks for the infos...

This post has been edited by airamana: 19 February 2009 - 09:20 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1