我正在使用std :: threads并且在我的设置中我的其他线程(可变数量,当前设置为10)正在使用如此多的容量,以至于我在任务管理器中使用的cpu达到应用程序的100%.这使我的主线程滞后,这应该是实时的(我认为这是滞后的原因).
我使用Intel Amplifier进行了调试,但没有其他线索可以解释为什么主线程应该滞后.我的次要线程都很忙.
是否有可能告诉线程它可以使用多少CPU最大值?如何确保我的其他线程不会影响主线程的性能?
线程初始化:
for (int i = 0; i < numberOfThreads; i++)
{
std::thread* thread = new std::thread(&MyClass::mWorker, this);
mThreads.push_back(thread);
}
Run Code Online (Sandbox Code Playgroud)
我的系统:i5-4590 3.3GHz,8 GB RAM,Windows 8 64位,Ogre3D图形引擎
我有一个SharedPreference,它计算我的应用程序的启动量.当我安装我的应用程序时,我希望它为0.然而它是14.我在数据库中观察到的同样奇怪的行为,已经存在于全新安装中.
我并不打算回收我的应用数据(例如在Google Cloud中).在我的设备帐户设置中,应用数据同步功能已开启.如果我将其关闭,并重新安装,我会观察到相同的行为.
任何人都观察到这样的行为?有没有办法阻止回收旧数据并强制正确安装?
我尝试将大小设置为零或删除java中打印文档的边框.它总是有一个标准的白色边框.
这是我的函数打印JPanel和一些组件:
public void printComponent(){
PrinterJob pj = PrinterJob.getPrinterJob();
pj.setJobName(" Print Component ");
pj.setPrintable (new Printable() {
@Override
public int print(Graphics pg, PageFormat pf, int pageNum) throws PrinterException {
if (pageNum > 0){
return Printable.NO_SUCH_PAGE;
}
Graphics2D g2 = (Graphics2D) pg;
g2.translate(pf.getImageableX(), pf.getImageableY());
TournamentView.this.paint(g2);
return Printable.PAGE_EXISTS;
}
});
if (pj.printDialog() == false)
return;
try {
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(OrientationRequested.LANDSCAPE);
PrinterResolution pr = new PrinterResolution(200, 200, PrinterResolution.DPI);
aset.add(pr);
pj.print( aset);
} catch (PrinterException ex) {
// handle exception
} …Run Code Online (Sandbox Code Playgroud) 以下函数以递归方式遍历列表并将其除以一半,并对子列表执行某些操作.如果列表大小为2,则递归会中断.我知道如果在迭代它时更改列表,则会发生并发修改异常.但我不使用迭代,它仍然会发生:
private static List<ParticipantSlot> divide(List<ParticipantSlot> list) {
int n = list.size();
//do something
if (n>2){
List<ParticipantSlot> l = divide(list.subList(0, n/2-1));
List<ParticipantSlot> r= divide(list.subList(n/2, n));
l.addAll(r);
return l;
}else{
return list;
}
}
Run Code Online (Sandbox Code Playgroud) 正如您在下面的可运行代码中所看到的,我尝试使用具有可扩展子框的Box.儿童盒可以改变它们的大小,这一切都很好.主要问题是大小始终相对于父级.但我希望它们具有特定的大小,以防万一没有地方使用JScrollPane.目前他们只收缩其他儿童盒子.
我尝试了Glue和Filler,但它没有用.胶水没有任何效果,填料具有副作用,始终保持一定的位置(即使ScrollPane正在运行).拥有如此多的自由空间是非常难看的.
所以,你知道防止盒子伸展孩子的好方法吗?
先感谢您!
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.border.TitledBorder;
public class ExpandableMenueDemo {
Box allBoxes;
ExpandableMenueDemo(){
allBoxes = Box.createVerticalBox();
TitledBorder title;
title = BorderFactory.createTitledBorder("Filter");
allBoxes.setBorder(title);
for (int i = 0 ;i<3;i++){
//generate collapsable components
SubBox b = new SubBox("SubBox"+i);
allBoxes.add(b.getSwingBox());
}
allBoxes.add(Box.createVerticalGlue());
}
public Container getMenue(){
return allBoxes;
}
public static void main(String[] args) {
JFrame frame = new JFrame();
ExpandableMenueDemo …Run Code Online (Sandbox Code Playgroud) 我有以下结构:
列表 - > List_Participant - >参与者
所以列表可能包含几个参与者.我尝试在java中阅读:
stat = con.createStatement();
ResultSet rs = stat.executeQuery("select * from list;");
// get the informations about the bracket sheet
while (rs.next()) {
string name = rs.getString("Name");
ResultSet rs2 = stat.executeQuery("select * from List_Participant where name= '"+name+"';");
while (rs2.next()) {
// get the participants
}
rs2.close();
}
rs.close();
Run Code Online (Sandbox Code Playgroud)
但这不起作用.我没有收到异常或任何其他输出.我建议打开第二个结果集将关闭第一个结果集因为我做了第一个结果集,将数据存储在一个arraylist中并关闭它,然后第二个结果集将工作,但这会导致性能不佳,因为我必须始终搜索arraylist.
什么可能是更好的解决方案?
编辑:解决方案是进行加入,我当前尝试:
select * from List_participant
INNER JOIN List ON List.name = List_participant.List
INNER JOIN participant ON List_participant.participant =participant.ROWID;
Run Code Online (Sandbox Code Playgroud)
我现在如何处理列,因为它们可能具有相同的名称?
我正在编写一个自定义插件,它在后面的代码中执行一些繁重的工作。我有时想发送进度更新,以便可以在 Ionic 中显示它。我在 CallbackContext 中找不到合适的方法。只能发送一次成功回调。如何实现发送进度回调?
private void doHeavyStuff(final CallbackContext callbackContext){
something.execute(new ResponseHandler() {
@Override
public void onProgress(String message) {
callbackContext.success(message); //what else ?
}
@Override
public void onFailure(String message) {
callbackContext.error(message);
}
@Override
public void onSuccess(String message) {
callbackContext.success(message);
}
});
}
Run Code Online (Sandbox Code Playgroud) 不知何故,它无法隐藏我的操作栏中的活动图标.我试过了:
ActionBar ab = activity.getActionBar();
ab.setDisplayHomeAsUpEnabled(假);
ab.setDisplayUseLogoEnabled(假);
这个bug在哪里?