Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6592485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:33:39+00:00 2026-05-25T17:33:39+00:00

I am given some skeletons of classes that I must implement (I personally don’t

  • 0

I am given some skeletons of classes that I must implement (I personally don’t really agree with the design of the program but I am not at mercy to change it 🙁 ) and they work in this manner:

I have a Game class which implements Runnable and represents a chess game.

A Server class will have a list of multiple Game classes that it keeps track of.

Ok this makes sense, Game implements Runnable so the Server can put each game in its own thread.

I am a bit confused at how java’s threads work.

What I know is the following:

After tying my Runnable class to a thread and calling the .start() method, the Runnable class’s run() method is called.

However, I have some other methods inside my Game class such as:

capturePiece()

playerMakesMove()

etc

In the current design, it is up to the Server to handle game actions. When a player wants to capture a piece, the Server will call game.capturePiece().

In this case, is capturePiece() being run on the Game thread, or the Server‘s thread? (the caller’s thread or the callee’s thread)

In this case, what would run() even do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:33:39+00:00Added an answer on May 25, 2026 at 5:33 pm

    Any method, in any programming language, executes in the same thread as the caller. When you call Thread.start() it runs in the same thread that called it.

    Now, you know that the run() method of a Thread does not execute in the same thread as start. But that is because start does not itself call run. You will have to read up more on threads to get the complete picture but just imagine that start only crates a new thread with some data structure (the Runnable) and the newly created thread looks at that data structure, identifies the Runnable and executes its run method.

    And that is really the only way control passes from one thread to another: one thread generates some data and other thread picks it up and processes it. Control does not pass from one thread to another, it is inter-thread communication and co-ordination.

    If the methods of Game are called by Server then the threads are not going to have anything to do, are they? But instead, if the Server does not call the method directly but instead represents the action as data then Game.run() can pick the action and perform it, in its own thread.

    Now the only question is where can Server put the data such that each Game.run(), running in its own thread knows to pick it up from. One option is to use BlockingQueue. The Server can put these Action objects in the queue and the Game thread can pick it up. How will the two know to use the same queue? There many different ways, one is for server to create the game with a queue and store a map on its side. As in the skeleton below:

    class Server {
        Map<Game, BlockingQueue> games = ....;
    
        void createGame() {
            BlockingQueue queue = ....;
            Game game = new Game(queue);
            games.put(game, queue);
        }
    
        void foo() {
           Game game = ....; 
           Action action = ....; // identify the Game
           map.get(g).add(action);
        }
    }
    
    class Game {
        BlockingQueue _queue;
    
        Game(BlockingQueue queue) { 
             _queue = queue; 
        }
    
        void run() {
            while (true) {
                Action nextAction = _queue.take();
                // perform the action
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been given some XML files that don't quite have a proper schema (I
Given some (English) word that we shall assume is a plural , is it
For my mobile programming course we've finally been given some free reign to design
I've been given some code that compiles fine on MSVC, and I'm trying to
Given some unix program which I've compiled, what might I need to do to
I have been given some vendor supplied driver code written in C that runs
Given some EventEmitter instance in Node.js , is it absolutely guaranteed that all events
I have been given some 'reports' from another piece of software that contains data
Given some jQuery object set, and also a subset of that set, is there
Given some code like this: class Json { } class Program { static void

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.