首页 \ 问答 \ Java - 如何在一段精确的时间内阻止正在运行的线程?(Java - How to block a running thread for an exact amount of time? [closed])

Java - 如何在一段精确的时间内阻止正在运行的线程?(Java - How to block a running thread for an exact amount of time? [closed])

我需要我的主线程阻止特定的时间。 我目前正在研究2D游戏,因为Thread.sleep(2)睡眠时间约为17秒,并且当你移动角色时图形略微滞后,因此它非常滞后。 有时它工作得很好(当我运行应用程序大约10次)时有时并非如此。 我知道Thread.sleep(long milliseconds)方法有一个延迟,但是有什么方法可以避免它或替代方法吗? 我已经尝试过LockSupport.parkNanos((long)2e6),但这并没有改变任何东西。


I need my main Thread to block for a specific amount of time. I am currently working on a 2D game and it's pretty laggy just because the Thread.sleep(2) sleeps for ~17 seconds and when you move the character, graphics are lagging slightly. Sometimes it's working just fine (when I ran the application about 10 times) and sometimes it's not. I know that there is a delay on the Thread.sleep(long milliseconds) method but is there any way to avoid it or an alternative? I already tried LockSupport.parkNanos((long)2e6) but that didn't change anything.


原文:https://stackoverflow.com/questions/35199629
更新时间:2023-06-28 13:06

最满意答案

我鼓励你熟悉使用熊猫从数据框中提取定量信息。 例如,你可以做一件简单的事情来获得你正在寻找的值(和其他有用的值):

planets.groupby("method").distance.describe().unstack()

它为每个方法打印一个有用值的表。

或者,如果你只是想要中位数:

planets.groupby("method").distance.median()

I would encourage you to become familiar with using pandas to extract quantitative information from a dataframe. For instance, a simple thing you could to do to get the values you are looking for (and other useful ones) would be:

planets.groupby("method").distance.describe().unstack()

which prints a table of useful values for each method.

Or if you just want the median:

planets.groupby("method").distance.median()

相关问答

更多
  • 在这方面,Seaborn似乎与matplotlib一样: tips = sns.load_dataset("tips") ax = sns.boxplot(x=tips["total_bill"], whis=[5, 95]) plt.grid(True) plt.boxplot(tips["total_bill"], whis=[5, 95], vert=False) plt.grid(True) 我猜seaborn只是传递给matplotlib方法。 docstring可能是从早期版本的matplo ...
  • 正如@mwaskom在下面的评论中指出我的初始答案,可以使用order参数在框之间创建空框位置。 import matplotlib.pyplot as plt import seaborn as sns import pandas as pd import numpy as np x = np.random.choice([1,3,9], size=1001) y = np.random.rand(1001)*(4+np.log(x)) df = pd.DataFrame({"x":x, "y":y}) ...
  • 我们用子图创建图: f, axes = plt.subplots(1, 2) 其中轴是每个子图的数组。 然后我们用参数ax告诉每个我们想要他们的子图。 sns.boxplot( y="b", x= "a", data=df, orient='v' , ax=axes[0]) sns.boxplot( y="c", x= "a", data=df, orient='v' , ax=axes[1]) 结果是: We create the figure with the subplots: f, ax ...
  • 使用color参数: import seaborn as sns tips = sns.load_dataset("tips") sns.boxplot(x="day", y="tip", data=tips, color="seagreen") Use the color parameter: import seaborn as sns tips = sns.load_dataset("tips") sns.boxplot(x="day", y="tip", data=tips, color="seag ...
  • 您需要编辑存储在ax.lines的Line2D对象。 下面是一个脚本来创建一个箱形图(基于这里的例子),然后根据你的问题中的样式编辑线条和艺术家(即没有填充,所有的线条和标记都是相同的颜色等) 您还可以修复图例中的矩形面片,但需要使用ax.get_legend().get_patches() 。 我还在第二个Axes上绘制了原始的boxplot作为参考。 import matplotlib.pyplot as plt import seaborn as sns fig,(ax1,ax2) = plt.su ...
  • 交换x和y列名称: import seaborn as sns sns.boxplot(x="weight_cat" y="Height", data=data) 目前,您正在尝试创建一个包含尽可能多的箱图的图表,因为有不同的高度值(24503)。 这对我的数据有用: 编辑 如果要水平显示箱线图,可以使用orient参数提供方向: sns.boxplot(x='Height', y='weight_cat', data=data, orient='h') 请注意,在这种情况下,交换x和y标签(如您的问题 ...
  • 有一个matplotlib轴实例ax (因为它是例如由seaborn图返回), ax = sns.boxplot(...) 允许获得标签 ax.get_xticklabels() 将文本从列表中删除的最简单方法是 texts = [t.get_text() for t in ax.get_xticklabels()] 包装文本也可以在运行中完成 texts = [textwrap.fill(t.get_text(), 10) for t in ax.get_xticklabels()] 甚至将文 ...
  • 这可能是一个丑陋的解决方案,但它有效,所以谁在乎 fig, ax = plt.subplots(1, 1) boxplot = sns.boxplot(x="Regularisierungsparameter", y="F1", data=data.sort("Regularisierungsparameter"), ax=ax) labels = ['%.5f' % float(t.get_text()) for t in ax.get_xticklabels()] ax.set_xticklabels( ...
  • 我鼓励你熟悉使用熊猫从数据框中提取定量信息。 例如,你可以做一件简单的事情来获得你正在寻找的值(和其他有用的值): planets.groupby("method").distance.describe().unstack() 它为每个方法打印一个有用值的表。 或者,如果你只是想要中位数: planets.groupby("method").distance.median() I would encourage you to become familiar with using pandas to ex ...
  • 您可以使用sns.boxplot和sns.stripplot函数中的order参数来订购“框”。 下面是一个如何执行此操作的示例(因为“最大到最低”并不完全清楚您的意思,即您希望根据条目对条目进行排序,我假设您要根据总和对它们进行排序对于他们的“距离”值,如果要根据不同的值对它们进行排序,您应该能够编辑解决方案以满足您的需求): import numpy as np import seaborn as sns sns.set(style="ticks", palette="muted", color_cod ...

相关文章

更多

最新问答

更多
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • 电脑高中毕业学习去哪里培训
  • 电脑系统专业就业状况如何啊?
  • IEnumerable linq表达式(IEnumerable linq expressions)
  • 如何在Spring测试中连接依赖关系(How to wire dependencies in Spring tests)
  • Solr可以在没有Lucene的情况下运行吗?(Can Solr run without Lucene?)
  • 如何保证Task在当前线程上同步运行?(How to guarantee that a Task runs synchronously on the current thread?)
  • 在保持每列的类的同时向数据框添加行(Adding row to data frame while maintaining the class of each column)
  • 的?(The ? marks in emacs/haskell and ghc mode)
  • 一个线程可以调用SuspendThread传递自己的线程ID吗?(Can a thread call SuspendThread passing its own thread ID?)
  • 延迟socket.io响应,并“警告 - websocket连接无效”(Delayed socket.io response, and “warn - websocket connection invalid”)
  • 悬停时的图像转换(Image transition on hover)
  • IIS 7.5仅显示homecontroller(IIS 7.5 only shows homecontroller)
  • 没有JavaScript的复选框“关闭”值(Checkbox 'off' value without JavaScript)
  • java分布式框架有哪些
  • Python:填写表单并点击按钮确认[关闭](Python: fill out a form and confirm with a button click [closed])
  • PHP将文件链接到根文件目录(PHP Linking Files to Root File Directory)
  • 我如何删除ListView中的项目?(How I can remove a item in my ListView?)
  • 您是否必须为TFS(云)中的每个BUG创建一个TASK以跟踪时间?(Do you have to create a TASK for every BUG in TFS (Cloud) to track time?)
  • typoscript TMENU ATagParams小写(typoscript TMENU ATagParams lowercase)
  • 武陟会计培训类的学校哪个好点?
  • 从链接中删除文本修饰(Remove text decoration from links)