小编wes*_*ton的帖子

尝试使用锁定时性能下降

我有一个MockHttpListener用于单元测试的回调.我添加了一个锁,如下所示:

public void HandleRequest(HttpListenerContext context)
{
    try
    {
        lock (m_guard)
        {
            do something short;
        }

        do the actual handling (longer)
    }
    catch (HttpListenerException e)
    {
        ...
    }
    catch (Exception e)
    {
        ...
    }
    ...
}
Run Code Online (Sandbox Code Playgroud)

我遇到了一个问题,即测试失败是由于我们有"太长时间"的标准(在添加锁之前我没有在测试中遇到这个问题.)

我尝试了许多方法来确定问题,解决问题的唯一方法就是在try块之外进行锁定:

public void HandleRequest(HttpListenerContext context)
{
    lock (m_guard)
    {
        do something short;
    }
    try
    {
        do the actual handling (longer)
    }
    catch (HttpListenerException e)
    {
        ...
    }
    catch (Exception e)
    {
        ...
    }
    ...
}
Run Code Online (Sandbox Code Playgroud)

在相对于try块的锁定位置影响测试完成所花费的持续时间方面,行为改变是一致的.

任何人都知道原因吗?

c#

9
推荐指数
1
解决办法
427
查看次数

什么忽略了 gradle 包装器?

设置

新的intellij安装,新的sourcetree安装,新的android项目,.gitignore已经初始化为:

*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
Run Code Online (Sandbox Code Playgroud)

问题

gradle 包装器中的文件,即gradle/wrapper/gradle.propertiesgradle/wrapper/gradle.jar被忽略。他们应该被添加

$git add gradle/wrapper/gradle-wrapper.jar 
The following paths are ignored by one of your .gitignore files:
gradle/wrapper/gradle-wrapper.jar
Run Code Online (Sandbox Code Playgroud)

它没有告诉我是哪个.gitignore文件。

没有.gitignoreingradle/gradle/wrapper

虽然我可以强制这样做,但我不想在未来的项目中忘记。

git sourcetree

9
推荐指数
1
解决办法
5659
查看次数

Proguard回溯输出混乱

我在这里有来自Android市场的一款游戏的堆栈跟踪.我已经取消了它,但我无法理解它!

我不是在错误本身中寻求帮助,而是如何解释这一点.

我从市场开始:

java.lang.IllegalArgumentException
at java.nio.Buffer.position(Buffer.java:299)
at com.a.a.k.o.a(Unknown Source)
at com.a.a.k.w.a(Unknown Source)
at com.a.a.k.w.onDrawFrame(Unknown Source)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1363)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)
Run Code Online (Sandbox Code Playgroud)

但是retrace.bat输出了这个,这个更长,所以我不知道com.aakoa是什么(例如).

java.lang.IllegalArgumentException
at java.nio.Buffer.position(Buffer.java:299)
at com.eaw.graphics.WorldViewShader.void glSetMVPMatrix(float[])(Unknown Source)
                                    void glSetNormalMatrix(com.eaw.graphics.AMatrix)
                                    void SetVertices(java.nio.FloatBuffer)
                                    void ApplyArgs(com.eaw.graphics.WorldViewShaderArgs)
at com.eaw.graphics.TriangleRenderer.void onDrawFrame(com.eaw.airrace.ILayer,com.eaw.airrace.StepOutput,boolean)(Unknown Source)
                                     void loadTexture$332cd44f(int[],int,int)
                                     void delayedLoadTexture(int[],int[],int,int)
at com.eaw.graphics.TriangleRenderer.void onDrawFrame(javax.microedition.khronos.opengles.GL10)(Unknown Source)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1363)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)
Run Code Online (Sandbox Code Playgroud)

在遮挡期间它是否将4个功能归为1?或者是什么?

android proguard

8
推荐指数
2
解决办法
2453
查看次数

Eclipse,在库中定义的开放声明

在Eclipse中,如果我按下F3或在我的某个库中的引用上打开声明,它将打开代码的只读副本.

起初我认为这非常有用,因为它提醒我它的库代码和更改可能会影响更多的项目.但是如果我想编辑,我发现必须手动查找.java文件是一件痛苦的事.

我可以:a)使它始终打开相关的.java文件,或者b)只要readonly副本打开,快速转到可编辑的.java文件.

java eclipse

8
推荐指数
1
解决办法
3364
查看次数

从字符串转换为任何基本类型

我有一个string和一个Type,我想返回string转换为该值的值Type.

public static object StringToType(string value, Type propertyType)
{
    return Convert.ChangeType(value, propertyType, CultureInfo.InvariantCulture);
}
Run Code Online (Sandbox Code Playgroud)

这将返回一个object我可以在属性设置值调用中使用的内容:

public static void SetBasicPropertyValueFromString(object target,
                                                   string propName,
                                                   string value)   
{
  PropertyInfo prop = target.GetType().GetProperty(propName);
  object converted = StringToType(value, prop.PropertyType);
  prop.SetValue(target, converted, null);
}
Run Code Online (Sandbox Code Playgroud)

这适用于大多数基本类型,除了nullables.

[TestMethod]
public void IntTest()
{ //working
    Assert.AreEqual(1, ValueHelper.StringToType("1", typeof (int)));
    Assert.AreEqual(123, ValueHelper.StringToType("123", typeof (int)));
}

[TestMethod]
public void NullableIntTest()
{ //not working
    Assert.AreEqual(1, ValueHelper.StringToType("1", typeof (int?)));
    Assert.AreEqual(123, ValueHelper.StringToType("123", typeof (int?)));
    Assert.AreEqual(null, …
Run Code Online (Sandbox Code Playgroud)

c#

8
推荐指数
1
解决办法
3713
查看次数

应该编译sdk低于目标sdk

关于SO的压倒性建议是编译SDK通常应该与目标SDK匹配.

同样,建议将此[compileSdk]与目标sdk版本匹配.

... CompileSDK(通常等于目标SDk版本)版本.

这里明确的建议是:

通常,您应该针对应用程序可以支持的最低版本的平台编译应用程序.

我总是编译sdk匹配目标sdk,但自从阅读以来我意识到我和许多SO答案都是错误的.

我的问题是,使它们匹配有什么害处,或者反过来说,拥有最低编译sdk版本的优势是什么?

android

8
推荐指数
1
解决办法
2001
查看次数

在xml编辑器中切换字符串资源的引用和值预览

当我在Android Studio中以xml值工作并参考@Strings/xy例如,我在视频中看到,实际上可以直接在同一个编辑器窗口中显示实际值.它基本上是切换到@String/xy"XYContent" 之间,但参考仍然存在.

我没有引用"ctrl + click",它strings.xml在新标签页面中打开(在我的情况下).

任何的想法?在帮助文件中找不到对此的任何引用.

xml android android-resources android-studio

8
推荐指数
2
解决办法
2540
查看次数

减少按钮内的文本填充

是否有可能减少普通Android按钮内的文本填充,以减少按钮的宽度?

当然,整个文本仍应可见.

android text button padding

7
推荐指数
2
解决办法
7710
查看次数

反序列化xml,包括命名空间

我试图反序列化一些XML,我无法获得命名空间/ xsi:type="Model"工作.如果xsi:type="Model"它不在XML中,它可以工作,但它必须在那里.如果我将命名空间从模型中删除,我会收到错误,如果我重命名它,我会得到一个空列表.

XML

<Vehicles xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Vehicle xsi:type="Model">
        <Id>238614402</Id>
    </Vehicle>
    <Vehicle xsi:type="Model">
        <Id>238614805</Id>
    </Vehicle>
</Vehicles>
Run Code Online (Sandbox Code Playgroud)

模型

[XmlRootAttribute("Vehicles")]
public class Vehicles
{
    public Vehicles() 
    {
        Vehicle = new List<Vehicle>();
    }

    [XmlElement(ElementName = "Vehicle", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
    public List<Vehicle> Vehicle { get; set; }
}


public class Vehicle
{
    [XmlElement("Id")]
    public int Id { get; set; }

}
Run Code Online (Sandbox Code Playgroud)

反序列化

XmlSerializer serializer = new XmlSerializer(typeof(Vehicles));
string carXML = "<Vehicles xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Vehicle  xsi:type=\"Model\"> <Id>238614402</Id> </Vehicle><Vehicle  xsi:type=\"Model\"> <Id>238614805</Id> </Vehicle></Vehicles>";

var cars = …
Run Code Online (Sandbox Code Playgroud)

c# xml xml-deserialization deserialization

7
推荐指数
1
解决办法
1130
查看次数

如何从json树反序列化?

假设我已经阅读了json树.

是否可以从中反序列化(不转换回字符串)?

public class TryDeserializeNode {

   public static class MyClass {

      private int x = 11, y = 12;

      public int getX() {
         return x;
      }

      public void setX(int x) {
         this.x = x;
      }

      public int getY() {
         return y;
      }

      public void setY(int y) {
         this.y = y;
      }
   }

   public static void main(String[] args) throws IOException {

      ObjectMapper mapper = new ObjectMapper();

      MyClass myClass = new MyClass();
      String string = mapper.writeValueAsString(myClass);

      JsonNode tree = mapper.readTree(string);

      // how …
Run Code Online (Sandbox Code Playgroud)

java json jackson

7
推荐指数
1
解决办法
148
查看次数