在锁定/解锁设备时,我找不到任何停止/恢复线程的工作解决方案,任何人都可以帮忙,或告诉我在哪里可以找到如何做到这一点?我需要在手机锁定时停止线程,并在手机解锁时再次启动它.
所以我有一个 java 服务器和客户端,数据被发送到服务器很好,服务器正在交互它,但我发现客户端需要很长时间才能响应服务器发送的内容,经过一段时间环顾四周,我发现我的服务器发送给客户端的数据比应该发送的数据长得多。
发送到客户端的数据包包含我发送的所有数据,但是它后面也有很多空白,我想解决这个问题,有人有什么想法吗?
我获取数据的代码是服务器上每个客户端的简单 for 循环,这将客户端数据添加到一个字符串中,并将该字符串添加到一个数据包中:
类 PlayerList
public static String getString()
{
String message = "";
for(int x = 0; x < list.size(); x++)
{
Player player = list.get(x);
if(message.equals(""))
{
message += player.name+";"+player.address+";"+player.pos[0]+";"+player.pos[1]+";"+player.fakeRotation+";"+player.rotation+";"+player.rotationSpeed+";"+player.speed+";"+player.sheildEnabled+";"+player.sheildStrength+";"+player.health;
}
else
{
message += ","+player.name+";"+player.address+";"+player.pos[0]+";"+player.pos[1]+";"+player.fakeRotation+";"+player.rotation+";"+player.rotationSpeed+";"+player.speed+";"+player.sheildEnabled+";"+player.sheildStrength+";"+player.health;
}
}
System.out.println(message);
return message;
}
Run Code Online (Sandbox Code Playgroud)
班级发送
while(Server.serverRunning)
{
for(int p = 0; p < PlayerList.list.size(); p++)
{
Player player = PlayerList.list.get(p);
try
{
byte[] buf = PlayerList.getString().getBytes();
//send the message to the client to the given address …
Run Code Online (Sandbox Code Playgroud) 我希望得到showGUI()方法,编译器说"this"不是静态变量,不能从静态上下文引用,我会用什么来代替"this"?我已经尝试过test.main(测试是它所在的包).我使用静态方法showGUI()的原因是因为我需要从另一个静态方法以及startup()方法调用该方法.以下是我的两个主要课程.
public class Main extends SingleFrameApplication {
@Override protected void startup() {
showGUI();
}
@Override protected void configureWindow(java.awt.Window root) {
}
public static Main getApplication() {
return Application.getInstance(Main.class);
}
public static void main(String[] args) {
launch(Main.class, args);
}
public static void showGUI() {
show(new GUI(this));
}
}
public class GUI extends FrameView {
public GUI(SingleFrameApplication app) {
super(app);
initComponents();
}
private void initComponents() {
//all the GUI stuff is somehow defined here
}
}
Run Code Online (Sandbox Code Playgroud)