在后台进程中分叉和线程有什么区别?(What is the difference between forking and threading in a background process?)

阅读它所述的spawn gem的文档:

默认情况下,spawn将使用fork来生成子进程。 您可以将其配置为通过在调用时通过告知spawn方法或通过配置环境来执行线程化。 例如,这就是告诉spawn在调用时使用线程的方法,

使用fork或thread之间的区别是什么,这两个决定的影响是什么,以及我如何知道使用哪个?


Reading the documentation for the spawn gem it states:

By default, spawn will use the fork to spawn child processes. You can configure it to do threading either by telling the spawn method when you call it or by configuring your environment. For example, this is how you can tell spawn to use threading on the call,

What would be the difference between using a fork or a thread, what are the repercussions of either decision, and how do I know which to use?


原文:https://stackoverflow.com/questions/10666997
2022-03-12 14:03

满意答案

用这个:

public YourView(Context context, AttributeSet attrs) {
    super(context, attrs);
    int[] set = {
        android.R.attr.background, // idx 0
        android.R.attr.text        // idx 1
    };
    TypedArray a = context.obtainStyledAttributes(attrs, set);
    Drawable d = a.getDrawable(0);
    CharSequence t = a.getText(1);
    Log.d(TAG, "attrs " + d + " " + t);
    a.recycle();
}

我希望你有一个想法


use this:

public YourView(Context context, AttributeSet attrs) {
    super(context, attrs);
    int[] set = {
        android.R.attr.background, // idx 0
        android.R.attr.text        // idx 1
    };
    TypedArray a = context.obtainStyledAttributes(attrs, set);
    Drawable d = a.getDrawable(0);
    CharSequence t = a.getText(1);
    Log.d(TAG, "attrs " + d + " " + t);
    a.recycle();
}

i hope you got an idea

相关问答

更多

Android自定义视图属性 - 不允许使用“颜色”作为属性名称(Android custom view attributes - 'color' as attribute name disallowed)

出于与无法使用background相同的原因,您无法使用color 。 它们已经在android命名空间中定义。 那么如何使用color或任何其他保留的属性名称? 通过使用已定义的那些,而不是创建新的。 代替 : <attr name="swatchColor" format="color"/> 用这个: <attr name="android:color"/> 始终确保使用android提供的那些。 只有当您认为它不符合您的需求时,请继续创建您自己的属性。 You can't use col...

如何解决:“实现与自定义视图的双向数据绑定时找不到属性'android:text'的getter?(How to solve: “cannot find getter for attribute 'android:text'” when implementing two-way data binding with custom view?)

很有趣,但我能够在帮助我解决这个问题的媒体上找到一篇很棒的文章 。 基本上我需要的是一个CustomEditTextBinder : @InverseBindingMethods( InverseBindingMethod( type = CustomEditText::class, attribute = "android:text", method = "getText" ...

Android:基于布局的自定义视图:如何?(Android: Custom view based on layout: how?)

以下是关于创建自定义聚合视图的一种方法的一些粗略步骤: 扩展RelativeLayout 在接受Context和AttributeSet的新类中提供一个构造函数,确保首先调用超类。 此时不要添加任何内容。 等到下一步。 重写onFinishInflate方法,您可以在其中通过Java代码添加内容或者扩充 XML资源 添加任何事件处理程序等 如果您的小部件需要设置属性,可以选择创建一个资源文件。 Here are some rough steps regarding one way to creat...

Android:自定义视图属性上的选择器(Android: Selector on custom View Attribute)

你错过了refreshDrawableState调用 public void setToggle(boolean val) { toggle = val; refreshDrawableState(); } 来自文档 调用此方法强制视图更新其可绘制状态。 you missed the refreshDrawableState call public void setToggle(boolean val) { toggle = val; ...

具有自定义xml属性的自定义视图:如何重新布局布局(Custom View with custom xml attribute: How to refeference a layout)

您确实可以在自定义视图的构造函数中扩展您的布局: public class MyCustomView extends /* LinearLayout, RelativeLayout, etc. */ { public MyCustomView(Context context, AttributeSet attrs) { super(context, attrs); initView(context, attrs); } public MyCu...

如何使用标准属性android:文本在我的自定义视图?(How to use standard attribute android:text in my custom view?)

用这个: public YourView(Context context, AttributeSet attrs) { super(context, attrs); int[] set = { android.R.attr.background, // idx 0 android.R.attr.text // idx 1 }; TypedArray a = context.obtainStyledAttributes(a...

jsp:attribute必须是标准或自定义操作的子元素(jsp:attribute must be the subelement of a standard or custom action)

我解决了它,因为我不能在<jsp:body>包含html和其他代码,所以使用<jsp:attribute>不会给我错误。 I solved it ,because I can not contain html and other code in <jsp:body> ,use <jsp:attribute> will not give me the error.

在我的自定义视图上阅读Android属性(Reading Android attributes on my custom view)

首先,我不确定是否可以为视图扩展RelativeLayout设置android:text 。 如果有可能在TextView实现中这样做: final Resources.Theme theme = context.getTheme(); a = theme.obtainStyledAttributes(attrs, com.android.internal.R.styleable.TextView, defStyleAttr, defStyleRes); text = a.getText(attr...

如何在自定义视图中获取android默认属性(How to get android default attributes in a custom view)

您可以将android:text添加到声明的syleable。 但一定不要重新声明它。 <declare-styleable name="CustomEditText"> <attr name="android:text" /> </declare-styleable> 然后从样式中获取此值,就像使用R.styleable.CustomEditText_android_text索引的任何其他属性R.styleable.CustomEditText_android_text 。 CharS...

下一个视图id作为android中的自定义属性(Next view id as a custom attribute in android)

将您的xml更改为: ... <mycustomview id="@+id/cv_1" xyz:nextviewId="@+id/cv_2"... /> <mycustomview id="@+id/cv_2" xyz:nextviewId="@+id/cv_3"... /> ... (注意nextviewId的@+id ) 这适用于Android 1.6+(Api Level 4+)。 RelativeLayout使用了完全相同的方法。 Change your xml to: ... <myc...

相关文章

更多

干干净净终结进程[转] Terminate process cleanly [reprint]

Terminate process cleanly[reprint] I often notic ...

zz Data Analysis Process

An interesting article....easy to understand. Summa ...

Becoming a data scientist

Data Week: Becoming a data scientist Data Pointed, ...

Hadoop执行分布式Process

要把N个超级大表导入HBase,N是按月来分的,表:亿+的行数,100+的字段。测试过sqoop,JD ...

multi-core solr deploy process(not complete)

How to set up Solr on Ubuntu 10.04 (or whatever) 0 ...

Become a Master Designer: Rule Three: Contrast, Contrast, Contrast

Part Three of Seven Easy Principles to Becoming a M ...

multi-core solr deploy process(not complete)

根据/etc/tomcat6/Catalina/localhost/solr.xml中部署的solr. ...

[转]So You Want To Be A Producer

pro-du-cer n. 1. Someone from a game publisher who ...

按钮样式

网页上有很多功能是通过链接方式传递参数,这种功能链接普通样式就是一个超链接退出,如果将超链接的样式变成 ...

解决Hadoop抛出的Task process exit with nonzero status of 134异常

首先,我说说碰到这个问题的原因 造成在tasktracker的log中出现错误: 2012-01-04 ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本