处理程序消息数据被下一条消息覆盖的Java线程问题

我有一个线程从蓝牙流中读取数据,该数据将数据发送到主UIThread上的处理程序(基于蓝牙聊天示例 )。 我发现了一个经常弹出的线程问题。 首先,一些代码供参考。 BluetoothService.java (只是读取incomming数据流的部分。在此代码运行之前已正确设置)。 public void run() { DebugLog.i(“BluetoothService”, “BEGIN mConnectedThread”); byte[] buffer = new byte[1024]; int bytes; // Keep listening to the InputStream while connected while (true) { try { // Read from the InputStream bytes = mmInStream.read(buffer); DebugLog.d(“BluetoothService”, new String(buffer, 0, bytes)); // Send the obtained bytes to the UI Activity […]

mongoDB:数组中不存在的文档的$ inc

我无法编写代码,这将能够增加数组中不存在的值。 让我们考虑mongo集合中的以下结构。 (这不是我们使用的实际结构,但它维持了这个问题) { “_id” : ObjectId(“527400e43ca8e0f79c2ce52c”), “content” : “Blotted Science”, “tags_with_ratings” : [ { “ratings” : { “0” : 6154, “1” : 4974 }, “tag_name” : “math_core” }, { “ratings” : { “0” : 154, “1” : 474, }, “tag_name” : “progressive_metal” } ] } 示例问题:我们希望将此文档添加到tags_with_ratings属性中,增加标记的评级,该标记尚未添加到数组中。 例如,我们希望为tag_name“dubstep”增加“0”值。 所以预期的行为是,mongo将这样的文档插入到“tags_with_ratings”属性中: { “ratings” : { “0” : […]

输出文件包含Mapper输出而不是Reducer输出

嗨我试图在独立模式下使用map reduce技术找到少数数字的平均值。 我有两个输入文件。它包含值file1: 25 25 25 25 25和file2: 15 15 15 15 15 。 我的程序运行正常,但输出文件包含mapper的输出而不是reducer输出。 这是我的代码: import java.io.IOException; import java.util.StringTokenizer; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.Reducer; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; import org.apache.hadoop.io.Writable; import java.io.*; public class Average { public static class SumCount implements Writable { public int […]

限制按钮点击次数

我制作了一个应用程序,用户按下按钮进入另一个活动,但我只希望用户共按下此按钮5次。 我尝试了以下代码,但它并没有阻止用户按下按钮超过5次,所以我猜测应用程序需要以某种方式记住点击? public void FoodClicks(View view){ if(this.counter == 5){ this.counter ++; } else { Button btn = (Button)findViewById(R.id.button); btn.setEnabled(false); } } ActivityMain.xml:

从lambda对象获取MethodHandle

来自java.lang.invoke.LambdaMetafactory : 用于评估lambda表达式的推荐机制是将lambda体转移到方法,调用invokedynamic调用站点,其静态参数列表描述function接口的唯一方法和desugared实现方法,并返回一个对象(lambda对象)实现目标类型。 从检查来看,这至少是Oracle JDK的作用。 我的问题:给定一个lambda对象有没有办法找到实现方法的名称(或句柄)? 或者,给定一个实现方法列表,有没有办法告诉哪一个对应于给定的lambda对象?

WebView第二次显示空白屏幕?

我目前正在开发一款应用程序,可在Android WebView中以桌面模式加载https://web.whatsapp.com/ whatsapp for web。 它在棒棒糖版本上工作正常,但在API 23及以上版本(棉花糖及以上)应用程序仅加载网站一次,如果按下重新加载按钮,它只显示一个空白屏幕! 这是Android API级别21上的代码正常工作但不是上面请帮助!! public class Main_web_view_frag extends android.support.v4.app.Fragment { public WebView Assignment_webView; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View slide_view = inflater.inflate(R.layout.assignment_main_webview, container, false); Assignment_webView = (WebView)slide_view.findViewById(R.id.webView); Assignment_webView.getSettings().setJavaScriptEnabled(true); Assignment_webView.setWebViewClient(new My_web_Browser()); Assignment_webView.loadUrl(“https://web.whatsapp.com/”); setDesktopMode(true); return slide_view; } private class My_web_Browser extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, […]

使用java访问嵌套的JSON对象值

{ “files”: { “f1.png”: { “intext”: “A”, “inval”: 0, “inbinary”: false }, “f2.png”: { “intext”: “A”, “inval”: 0, “inbinary”: true } } } 如何在f1.png值未修复时访问inval的值。 即文件的名称可以是任何东西,它是未知的,那么如何使用Java访问此JSON中各种文件的inval字段的值?

在LDAP中实现超时

我一直在处理我们使用LDAP获取用户详细信息的应用程序。 有时需要更多时间来获取用户详细信息。 我想在获取详细信息的方法上实现超时 ,以便在最坏的情况下我们可以避免在服务器中挂起事务。 这里我们使用LdapUtil类,我们在其中配置了LdapTemplate类来获取所需的详细信息。 我们如何在LDAP方法上实现超时? (在本例中为ldapTemplate.search(…)方法) public class LdapUtil { @Autowired(required = true) @Qualifier(value = “ldapTemplateApp”) LdapTemplate ldapTemplate; public Set findProducts(String UserId) { final Set products = newHashSet(); // Lookup the user String usrFilter = String.format(USERID_FILTER, globalUserId); ldapTemplate.search(“ou=Members”, usrFilter, // note this line new NameClassPairCallbackHandler() { public void handleNameClassPair(NameClassPair nameClassPair) { SearchResult result = […]

如何使用getCropAndSetWallpaperIntent(Uri imageUri)工作?

那么,有两个问题与此相同( 如何在WallpaperManager中使用getCropAndSetWallpaperIntent方法? 如何使用getCropAndSetWallpaperIntent? ),但两者都没有答案。 希望得到一个答案,我问这个 – 如何使这个方法工作。 这对我的大脑没有帮助的http://developer.android.com/reference/android/app/WallpaperManager.html#getCropAndSetWallpaperIntent(android.net.Uri) 。 这不起作用 WallpaperManager wallpaperManager = WallpaperManager.getInstance(MainActivity.this); Uri uri = Uri.parse(“android.resource://lv.revo.inspicfootballhd/drawable/v1”); Intent intent = new Intent(wallpaperManager.getCropAndSetWallpaperIntent(uri)); startActivity(intent); logcat显示了这一点 5891-5891/? E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: lv.revo.inspicfootballhd, PID: 5891 java.lang.IllegalArgumentException: Image URI must be of the content scheme type at android.app.WallpaperManager.getCropAndSetWallpaperIntent(WallpaperManager.java:760) at lv.revo.inspicfootballhd.MainActivity.onTouch(MainActivity.java:236) at android.view.View.dispatchTouchEvent(View.java:7701) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at […]

通知通道关闭到实现org.springframework.amqp.rabbit.connection.ConnectionListener的类

我们使用Spring-AMQP提供的ConnectionListener接口在底层连接上保留一个选项卡。 通过自动恢复创建通道,心跳设置为10分钟(针对某些产品需求)。 我的观察是即使在底层的rabbitMQ死后,connectionListener.onClose()方法也不会被调用近10分钟。 我们还对API执行运行状况检查,并使用connectionListener.isOpen()方法确定连接的状态。 并且因为SimpleConnection类中的这个代码块 @Override public boolean isOpen() { return delegate != null && (delegate.isOpen() || this.delegate.getClass().getSimpleName().contains(“AutorecoveringConnection”)); } 当连接自动恢复时,始终返回true。 因为Health API在连接中断后10分钟内没有得知连接失败。 是否有任何建议的方法来通知ConnectionListener通道关闭,因为isOpen方法显然无法满足需求? 正在实现ShutDownlistener的方式吗? 由于我们没有访问connectionListerner中的通道而无法直接执行connection.addConnectionListerner(this)。 从connectionFactory shutdownCompleted方法是否可以调用onClose或connectionListener上的任何其他方法来通知它关闭? 还有其他想法吗?