Change main thread

How can you change the class in the main thread running update ()?
I use my thread class are sure that the local buffer objects, as ThreadLocal I find too slow.

Please try to rephrase the question or explain more about what you are really trying to do. The question doesn’t really make sense as written.

For example, we have no idea why you’d even want a ThreadLocal or something similar.

…and ThreadLocal should not be slow anyway. So you are doing something very strange.

game loop, executed in the thread java.lang.Thread, and I need that he carried in the flow my client.GameThread extends java.lang.Thread

Well i would really like to help, but your limited english makes it almost impossible to understand anything.

I guess what you are searching for is actuall the enqueue Method in application, that allows to execute code from anywhere in the renderthread.

@javasabr said: game loop, executed in the thread java.lang.Thread, and I need that he carried in the flow my client.GameThread extends java.lang.Thread

What do you mean by “carried in the flow”? I either don’t understand what you mean or you are wrong about needing it.

You will have to provide a lot more information than you have.

[java]
public void create(boolean waitFor){
if (created.get()){
logger.warning(“create() called when display is already created!”);
return;
}

    new Thread(this, "LWJGL Renderer Thread").start();
    if (waitFor)
        waitFor(true);
}

[/java]
Content executed in the java.lang.Thred . I want to change the implementation of its flow.

But why? What are you really trying to do?

I don’t think you need to do it. I think you are very confused.

Binding local objects to the thread, is much more effective.

I’m done.

Your one line at a time responses tell us nothing useful. You can use ThreadLocal just fine. We could show you if you provided more information but you won’t.

So good luck.

is what I use on servers
[java]public static final LocalObjects get()
{
return ((ServerThread) Thread.currentThread()).getLocal();
}[/java]

[java]public class ServerThread extends Thread
{
/** набор локальных объектов для серверного потока */
private LocalObjects local;

public ServerThread()
{
	this.local = new LocalObjects();
}

public ServerThread(Runnable target)
{
	super(target);
	
	this.local = new LocalObjects();
}

public ServerThread(ThreadGroup group, Runnable target, String name)
{
	super(group, target, name);
	
	this.local = new LocalObjects();
}

/**
 * @return набор локальных объектов дял потокаю
 */
public LocalObjects getLocal()
{
	return local;
}

}[/java]
I want to be able to use the same pattern on both the client

Just use ThreadLocal instead.

ThreadLocal is much less effective >_<

solved the problem by bad
[java]
package client;

import com.jme3.system.AppSettings;
import com.jme3.system.lwjgl.LwjglDisplay;

/**

  • Модель контекста игры.

  • @author Ronn
    /
    public final class GameContext extends LwjglDisplay
    {
    /
    * игровой поток рендера экрана */
    private GameThread thread;

    @Override
    public void create(boolean waitFor)
    {
    if(created.get())
    return;

     thread = new GameThread(this);
     thread.setName("LWJGL Renderer Thread");
     thread.start();
     
     if(waitFor)
     	waitFor(true);
    

    }

    /**

    • @return игровой поток рендера экрана.
      */
      public GameThread getThread()
      {
      return thread;
      }

    @Override
    protected void initContextFirstTime()
    {
    settings.setRenderer(AppSettings.LWJGL_OPENGL2);

     super.initContextFirstTime();
    

    }
    }

[/java]
and

[java]@Override
public void start(Type contextType)
{
settings.setRenderer(“CUSTOM” + GameContext.class.getName());

	super.start(contextType);
}[/java]

=)

@javasabr said: ThreadLocal is much less effective >_<
Why do you think so? I don't, like pspeed.

Why not just store the data in the SimpleApplication rather than storing it on the thread at all?

@normen said: Why do you think so? I don't, like pspeed.
LocalThread : Thread.currentThread() -> hashMap.get(thread) -> target instance; GameThread : Thread.currentThread() -> cast() -> get field instance
@zarch said: Why not just store the data in the SimpleApplication rather than storing it on the thread at all?
this is local thread objects

No its not. This object only exists on your specific thread and is attached to it. Therefore each thread that has this object has created this object.

Thread local objects are where lots of different threads all have their own version of an object.

If you only access it from one thread then great, just put it somewhere and only access it from that thread…

@javasabr said: LocalThread : Thread.currentThread() -> hashMap.get(thread) -> target instance; GameThread : Thread.currentThread() -> cast() -> get field instance
I don't see the "much" here. A cast is pretty expensive on its own right if we're down to that level, you know that?