使用计时器重复字符 [英] using timers for repeating characters

查看:129
本文介绍了使用计时器重复字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编程新手。我正在研究一个将字符发布到前台应用程序的程序。一切都很好,除了重复的字符。我认为使用任务计时器是可行的方法,但似乎当JVM清理它的垃圾时,试图赶上,因此在预设的工作周期中发布更多周期。


任何提示使用java来控制重复的字符或任务?

解决方案

嗨mauiboy!欢迎来到TSDN!


我正在开发一个将字符发布到前台应用程序的程序。



您是说,您将单个字符发送到程序的不同部分还是完全不同的应用程序?然后接收器应该打印收到的字符?


一切正常,除了重复字符。



因此,它可以正常工作,比如{''n'',''我',''c'',''e''}但是不是{''b'','e'','t'','t'','e'',''r''}? (因为连续有2个相同的字符。)或者你的意思是,只发送一个字符就可以了,但是当你发送多个字符时,它会出错?


是的只是正如你所描述的那样:{''b'','e'','t'','t'',''e'',''r''}我很难控制我的重复计时器,当我需要发布一个单字符ex:{''b'','e'','t'','t'','e'',''r'', ''r''}。代码看起来像这样:


protected void repeatTimer()

{

repeatTimer = new Timer();

updateTask = new TimerTask()

{

public void run()

{

if(mRepeatEnabled!= false)

{

//执行重复任务

}

}

};

repeatTimer.schedule(updateTask,1000,100);

}


它可以重复字符,但随机发布双倍当我只想要单个角色的帖子时,三重复字符。


我尝试在需要时启动计时器&当我不知道但我遇到了太多线程运行错误的问题时停止它。


我也尝试了2个定时器,一个用于延迟第二个定时器。它工作得更好,但仍然发布随机双字符。


也许我不应该使用任务计时器,必须尝试使用​​wait()和invokelater()。


任何想法?



任何想法?



不,对不起;我从你所描述的内容中了解到了zilch。什么是如此独特

关于重复(原文如此)字符?你想对他们做什么,

会让他们与独特角色如此不同?需要详细说明吗?


亲切的问候,


Jos


programming newbie. I''m work on a program that post characters into foreground application. everything is working nicely except for repeating characters. I thought using a task timer was the way to go but it seems that as the JVM cleans its garbage the time tries to catchup therefore posting more cycles in it preset duty cycle.

any hints on using java to control repeating characters or tasks?

解决方案

Hi mauiboy! Welcome to TSDN!

I''m work on a program that post characters into foreground application.

Do you mean, that you send single characters to a different part of your program or a completely different application? Then the receiver should print the received character?

everything is working nicely except for repeating characters.

So, it works fine with, say {''n'',''i'',''c'',''e''} but not with {''b'',''e'',''t'',''t'',''e'',''r''}? (As there are 2 equal characters in a row.) Or do you mean, that sending just one character is fine, but when you send more than one, it goes wrong?


Yes just as you described: {''b'',''e'',''t'',''t'',''e'',''r''} i''m having a hard time controlling my repeat timer when I need to post a SINGLE character ex: {''b'',''e'',''t'',''t'',''e'',''r'',''r''} . the code looks something like this:

protected void repeatTimer()
{
repeatTimer = new Timer();
updateTask = new TimerTask()
{
public void run()
{
if ( mRepeatEnabled != false )
{
// Perform repeat the task
}
}
};
repeatTimer.schedule(updateTask, 1000, 100);
}

it works repeating characters but randomly post double and sometimes triple repeating characters when I only want single character post.

I tried Starting the timer when i need it & Stopping it when i don''t but I ran into the problem of too many threads running error.

I also tried 2 timers, one for delaying the second timer. It worked better but still random double characters are posted.

maybe I shouldn''t be using task timers and must try using wait() and invokelater().

any ideas?


any ideas?

Nope, sorry; I understand zilch from what you described. What is so unique
about repeating (sic) characters? And what do you want to do with them that
makes them so different from unique characters? Care to elaborate?

kind regards,

Jos


这篇关于使用计时器重复字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆